1.安装vue-router
npm i vue-router -s
2.书写路由文件routers.js,放在src根目录下
import home from "./components/home.vue"
import zhyu from "./components/Zhyu.vue"
export default[
{
path:"/", component:home
},
{
path:"/zhyu", component:zhyu
},
]
3.在vue项目的main.js中进行配置
import VueRouter from 'vue-router'
import Routes from "./routers.js"
vue.use(VueRouter)
const router = new VueRouter({
routes:Routes,
mode:'history'
})
new Vue({
router:router,
render: h => h(App),
}).$mount('#app')