简体   繁体   English

如何在 Nuxt 中使路由区分大小写

[英]How to make routes case sensitive in Nuxt

I use nuxt.js + vue.js.我使用 nuxt.js + vue.js。 I need to create case sensitivity of routers.我需要创建路由器的区分大小写。 I found the following property: caseSensitive.我发现了以下属性:caseSensitive。 I'm trying to put it into nuxt.config but it doesn't work, the transition is possible by links in upper case.我试图将它放入 nuxt.config 但它不起作用,可以通过大写链接进行转换。 If I directly change the file ~project/.nuxt/router.js, everything works correctly.如果我直接更改文件 ~project/.nuxt/router.js,一切正常。 Help me to figure it out.帮我想办法。

  router: {
    extendRoutes (routes) {
      for (let key in routes) {
        routes[key]['caseSensitive'] = true
      }
    }

Your code seems to be good.你的代码看起来不错。 I have tested it, here is mine :我已经测试过了,这是我的:

// nuxt.config.js
router: {
  extendRoutes(routes) {
    for (const key in routes) {
      routes[key].caseSensitive = true
    }
  }
}

To be more accurate, the nuxt documentation allows to customize routes with router.extendRoutes property in nuxt.config.js .为了更准确,nuxt 文件允许定制与路线router.extendRoutes物业nuxt.config.js As it said, for each route :正如它所说,对于每条路线:

The schema of the route should respect the vue-router schema路由的模式应该尊重 vue-router 模式

So you need to look at the documentation of vue-router where you can find the caseSensitive property.所以你需要查看vue-router的文档,在那里你可以找到caseSensitive属性。

Important note 1 : This option is available for Vue 2.6.0+ available for Nuxt 2.5.0.重要说明 1:此选项适用于 Vue 2.6.0+,适用于 Nuxt 2.5.0。 So Nuxt version must be at least >= 2.5.0.所以 Nuxt 版本必须至少 >= 2.5.0。

Important note 2 : Be sure to call the right url and make your cache empty.重要说明 2:请务必调用正确的 url 并使缓存为空。 I had the same issue because when I enter my url into Chrome search input browser, chrome automatically changed it into lowercase.我遇到了同样的问题,因为当我在 Chrome 搜索输入浏览器中输入我的 url 时,chrome 会自动将其更改为小写。 In fact it used history of my previous request and not the request I wanted.事实上,它使用了我之前请求的历史记录,而不是我想要的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM