- vue-router中默认使用的是hash模式,也就是会出现URL中带有#号
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
const Home = ()=> import('../views/Home');
const About = ()=> import('../views/About');
const User = ()=> import('../views/User');
const routes = [
{
path: '/',
name: 'Home',
components:{
default:Home,
About,
User
}
},
{
path: '/about',
name: 'About',
redirect:{name:'Home'}, //路由重定向
components:{
default:Home,
User,
About,
}
},
{
path:'/user',
component: User,
//子路由
children:[
{
path:'',
component:MyOrder
},
{
path:'page/:id',
alias:['p/:id', 'x/:id'], //路由别名
component:MyPage,
meta:{
title:'5555555555555'
}
},
]
}
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
// history:createWebHashHistory(process.env.BASE_URL),
routes
})
export default router;