前面完成了项目的结构划分,也进行了样式的重置以及全局变量的配置,现在开始该项目的路由配置
Vue-Router
npm install vue-router # router 属于是生产依赖
越来越有函数式编程的感觉了
import { createRouter, createWebHashHistory } from 'vue-router'
const router = createRouter({
history: createWebHashHistory(),
routes: []
})
export default router
main.ts
中挂载const app = createApp(App)
app.use(router)
app.mount('#app')
import { createRouter, createWebHashHistory } from 'vue-router'
const router = createRouter({
history: createWebHashHistory(),
routes: [
{
path: '/',
redirect: '/main'
},
{
path: '/login',
component: () => import('../views/Login/index.vue')
},
{
path: '/main',
component: () => import('../views/Main/index.vue')
},
{
path: '/:pathMatch(.*)',
component: () => import('../views/NotFound/index.vue')
}
]
})
export default router