Vue怎么定义嵌套路由

2022-10-14 09:11:15

1.首先,在新建一个html项目,并在项目中引入vue和vue-router;

import Vue from 'vue'

import Router from 'vue-router'

3.vue和vue-router引入好后,在项目中使用Vue.use方法注册路由;

Vue.use(Router)

3.路由注册好后,继续在项目中引入home和game两个组件;

import home from "./home.vue"

import game from "./game.vue"

4.最后,home和game组件引入后,在项目中使用const routes语句即可定义嵌套路由;

const routes = [

{ path: "/", redirect: "/home" },

{

path: "/home", component: home,

children: [

{ path: "/home/game", component: game }

]

}

]