vue—router嵌套路由设置及默认选择

嵌套路由

应用场景:用vue-router 设置一个页面的路由的时候,在其页面组件内也需要用到,用一个项目来举例子 我在app.vue中设置路由出口对其他页面组件.设置路径,比如home 首页设置,在router文件夹index.js中设置

routes: [
	{
		path: '/',
		component: home,
	    },
	    ]

如果我要在首页中也设置一个路由出口时候
就要在index.js中配置children

  routes: [
	{
		path: '/',
		component: home,
	    children: [
		{
      path: '/',
      component: Tuijian
     
    },{
      path: 'Tuijian',
      component: Tuijian
     
    }
    ]

这样就可以在home中设置默认路由为Tuijian了

猜你喜欢

转载自blog.csdn.net/weixin_42360556/article/details/83105531