javascript - Vue 嵌套路由不显示其组件并且没有错误

标签 javascript vue.js vuejs2 vue-component vue-router

当我访问 URL profile/admin 时,我会看到配置文件组件,但是,如果我尝试 URL profile/admin/locationsprofile/admin/ map ,我不加载 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>

map 组件模板:

<template>
    <div class="wrapper">
        <p>Location</p>
    </div>
</template>

最佳答案

您的 route 有拼写错误 - 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'}
    ]},
];

关于javascript - Vue 嵌套路由不显示其组件并且没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54265159/

相关文章:

javascript - 即使提供了 Pingdom 凭据也会丢失

javascript - 如何在 Vuejs 中停止执行直到 get 请求完成

javascript - 在 VueJS 组件中引用静态资源

vue.js - vue/cli中router中的base参数有什么用?

javascript - 循环 html 表并选中复选框(JQuery)

javascript - 为什么 "date"和 "time"条目在 Google Chrome Mobile 中显示不正确?

css - 如何在两个 css 样式文件(rtl、ltr)vue.js 之间切换

vue.js - Vue-Router 使用 props 传递数据

javascript - 如何通过修改.npmrc文件在Travis上运行lerna发布?

vue.js - 使用目标 wc 构建选项时,vue-cli 不会将代码转换为 es5 或 commonjs