vue多页面怎么使用new VueRouter变为history模式
使用new VueRouter将路由模式改为history模式的步骤如下:
-
在项目中找到router文件夹下的index.js文件(如果没有则需要新建)
-
在该文件中导入Vue和VueRouter:
import Vue from 'vue'
import VueRouter from 'vue-router'
- 启用VueRouter:
Vue.use(VueRouter)
- 创建路由实例并指定路由模式为history:
const router = new VueRouter({
mode: 'history',
routes: [
// 定义路由
]
})
- 将路由实例注入到Vue实例中:
new Vue({
router,
render: h => h(App)
}).$mount('#app')
- 完成以上步骤后,路由就已经成功改为history模式了。在浏览器地址栏中输入路由地址时,不再需要添加#号
原文地址: https://www.cveoy.top/t/topic/eaBE 著作权归作者所有。请勿转载和采集!