我关注the official example,但我不知道为什么我会出现这个js错误的空白页
vue-router.esm.js?fe87:10未捕获错误:[vue-router]" path"在路线配置中是必需的。
这是我的两页:
/:language/bar /:language/foo
+------------------+ +-----------------+
| +---------+ | | +---------+ |
| | header | | | | header | |
| +---------+ | | +---------+ |
| +--------------+ | | +-------------+ |
| | bar | | +------------> | | foo | |
| | | | | | | |
| +--------------+ | | +-------------+ |
+------------------+ +-----------------+
这就是我尝试这样做的方式。
我的入口点js文件:
import Vue from 'vue';
import router from './router';
// import some components
let vm = new Vue({
el: '#app',
router,
components: {/*imported components*/},
});
vm.$language.current = vm.$route.params.language;
我的入口点
<body>
<div id="app">
<!-- this is the header, the common part -->
<navbar fullname=''></navbar>
<router-view></router-view>
</div>
</body>
我的路由器
import Vue from 'vue';
import Router from 'vue-router';
// import foo and bar components
Vue.use(Router);
let routes = [
{
path: '/:language',
name: 'homepage',
children: [
{
path: 'foo',
component: Foo
},
{
path: 'bar',
component: Bar
},
]
}
];
export default new Router({routes,});
我的foo组件
<template>
<div>
<h1>FOO</h1>
</div>
</template>
<script>export default {};</script>
如何解决此错误?
答案 0 :(得分:1)
您还应该为父级添加组件。
答案 1 :(得分:0)
注意: 1.尝试使用本地注册的组件 2.对于嵌套路由器:
const router = new VueRouter({
routes: [
{ path: '/language/:id',
component: language,
children: [
{
// Bar will be rendered inside language's <router-view>
// when /language/:id/bar is matched
path: 'bar',
component: Bar
},
{
// Foo will be rendered inside language's <router-view>
// when /language/:id/foo is matched
path: 'foo',
component: Foo
}
]
}
]
})
export default {
name: "Foo"
};