优秀的编程知识分享平台

网站首页 > 技术文章 正文

路由模式-将路由改成history模式(路由转换)

nanyue 2024-08-11 20:40:04 技术文章 10 ℃


- hash模式带#,#后面的地址变化不会引起页面的刷新

- history没有#,地址变化会引起页面刷新,更符合页面地址的规范(开发环境不刷新-webpack配置)

- 将路由模式修改成history模式-代码位置(**src/router/index.js)**

const createRouter = () => new Router({
        mode: 'history', // require service support
        scrollBehavior: () => ({ y: 0 }),
        routes: constantRoutes // 默认引入静态路由
        })

更改mode属性即可。

Tags:

最近发表
标签列表