PS: 僅記錄自己不熟的概念。
一、嵌套路由:
根目錄path要加 / ,子路由path則不用
const routes = [
{
path: '/user',
component: User,
children: [
{
path: 'profile',
component: UserProfile,
},
],
},
]
二、命名路由:
name必須唯一值,不可重複
三、命名視圖:
一個SFC檔案存在多個router-view時
<router-view class="view left-sidebar" name="LeftSidebar" />
<router-view class="view main-content" />
<router-view class="view right-sidebar" name="RightSidebar" />
路由表components,必須加上s
const routes = [
{
path: '/',
components: {
default: Home,
LeftSidebar,
RightSidebar,
},
},
],
四、重定向和别名(Redirect and Alias)
const routes = [
{
path: '/users',
component: UsersLayout,
children: [
// 为这 3 个 URL 呈现 UserList
// - /users
// - /users/list
// - /people
{ path: '', component: UserList, alias: ['/people', 'list'] },
],
},
]
alias是一個陣列
它可加/,表示從根目錄開始