首页 > 解决方案 > Vue.js - vue-router 的基本 URL 是否区分大小写?

问题描述

我有一个使用vue-router模块的 Vue.js 应用程序。

export default new Router({
    base: '/CDP/V2',
    mode: 'history',
    routes: [
       {
            path: '/home',
            name: 'home',
            component: HomeApp
        }
    ]
})

vue-router 的基础是否url区分大小写?

如果是的话,我怎样才能让它不区分大小写?我想让“V2”部分不区分大小写

谢谢

标签: javascriptvue.jsvuejs2vue-componentvue-router

解决方案


是的,它区分大小写,你可以检查一下sample code,为了使它不敏感,请尝试以下代码:

// Define router
const router = new VueRouter({
  base: config.basePath,
  routes,
  mode: 'history'
})

// Route case-sensitivity hotfix
if (router.mode === 'history') {
  router.history.getCurrentLocation = function() {
    let path = window.location.pathname
    let base = router.history.base

    // Removes base from path (case-insensitive)
    if (base && path.toLowerCase().indexOf(base.toLowerCase()) === 0) {
      path = path.slice(base.length)
    }

    return (path || '/') + window.location.search + window.location.hash
  }
}

有关更多详细信息,请检查此issue


推荐阅读