我一直在vue-router docs中搜索索引路由,但无法找到如何执行此操作:
我有
const routes = [
{ path: '/:slug', component: Project }
];
我想要的是为" /"指定一个硬编码的slug。 (root),并将Project组件用于此路径。像(这是错误的):
const routes = [
{ path: '/', {'slug':'home-project'}, component:Project})
{ path: '/:slug', component: Project }
];
非常感谢!
答案 0 :(得分:0)
好的,这很容易
const routes = [
{ path: '/', component: Project }
{ path: '/:slug', component: Project }
];
然后在Project:
let slug = this.$route.params.slug;
if (!slug) {
slug = 'some-default-slug';
}