【问题标题】:Index route with hardcoded data带有硬编码数据的索引路由
【发布时间】:2016-10-26 08:32:57
【问题描述】:

我一直在 vue-router 文档中搜索索引路由,但找不到如何执行此操作:

我有

const routes = [
    { path: '/:slug', component: Project }
];

我想要的是为“/”(根)指定一个硬编码的 slug,并将 Project 组件也用于此路径。类似的东西(这是错误的):

const routes = [
    { path: '/', {'slug':'home-project'}, component:Project})
    { path: '/:slug', component: Project }
];

非常感谢!

【问题讨论】:

    标签: vue-router


    【解决方案1】:

    好的,这很容易

    const routes = [
        { path: '/', component: Project }
        { path: '/:slug', component: Project }
    ];
    

    然后在项目中:

    let slug = this.$route.params.slug;
    if (!slug) {
        slug = 'some-default-slug';
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-13
      • 1970-01-01
      • 2011-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-02
      • 2017-05-08
      相关资源
      最近更新 更多