当我访问URL profile/admin
时,会看到配置文件组件,但是,如果尝试URL profile/admin/locations
或profile/admin/map
,则不会加载“地图”或“位置”组件。有什么想法吗?
有关路线:
import Home from './components/Home.vue';
import Profile from './components/Profile.vue';
import Map from './components/Map.vue';
import Locations from './components/Locations.vue'
export const routes = [
{ path: '', component: Home, name: 'Home'},
{ path: '/profile/:username', component: Profile, name: 'Profile', chilren: [
{ path: '/profile/:username/locations', component: Locations, name: 'Locations'},
{ path: '/profile/:username/map', component: Map, name: 'Map'}
]},
];
配置文件组件模板:
<template>
<div class="wrapper">
<p>Profile</p>
<router-view></router-view>
</div>
</template>
位置组件模板:
<template>
<div class="wrapper">
<p>Location</p>
</div>
</template>
地图组件模板:
<template>
<div class="wrapper">
<p>Location</p>
</div>
</template>
答案 0 :(得分:3)
您的路线中有错别字-chilren
,而不是children
。
您无需在子级路由中指定完整路径。正确的做法:
export const routes = [
{ path: '', component: Home, name: 'Home'},
{ path: '/profile/:username', component: Profile, name: 'Profile', children: [
{ path: 'locations', component: Locations, name: 'Locations'},
{ path: 'map', component: Map, name: 'Map'}
]},
];