【问题标题】:How to change nuxt.js router to use custom path?如何更改 nuxt.js 路由器以使用自定义路径?
【发布时间】:2019-02-12 09:24:18
【问题描述】:

对于一个软件开发营销网站,我有 30 多个登录页面,我喜欢将它们保存在 ./pages/landing 文件夹中。因此,显然./pages/landing 中的文件可以通过以下方式访问,例如:

www.lorem.com/landing/python-development-experts/
www.lorem.com/landing/java-development-experts/

但我需要从路径中删除 /landing/ 并且仍然希望将文件保留在 ./pages/landing 文件夹中,但需要使用此路径访问文件:

www.lorem.com/python-development-experts/
www.lorem.com/java-development-experts/

请帮忙,谢谢。

【问题讨论】:

    标签: vue.js nuxt.js


    【解决方案1】:

    这是我在nuxt.config.js中所做的

    router: {
      extendRoutes: (routesIn) => {
        routesIn.forEach((r) => {
          if (r.path.includes('/landing/')) {
            r.path = r.path.replace('/landing', '');
          }
        });
        return routesIn;
      },
    },
    

    【讨论】:

    • 看起来这可能是一个很好的解决方案。今天早上我试图玩弄路线,但似乎没有其他任何工作。
    【解决方案2】:

    您可以通过此链接扩展您的路线结帐

    https://github.com/nuxt/nuxt.js/issues/112

    也许它的帮助! 谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 2020-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      • 1970-01-01
      相关资源
      最近更新 更多