【问题标题】:Vue.js - Is base url of vue-router case sensitive?Vue.js - vue-router 的基本 URL 是否区分大小写?
【发布时间】:2020-06-13 15:25:59
【问题描述】:

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

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

vue-router 的 base url 区分大小写吗?

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

谢谢

【问题讨论】:

    标签: javascript vue.js vuejs2 vue-component vue-router


    【解决方案1】:

    是的,它区分大小写,您可以检查此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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-16
      • 1970-01-01
      • 2016-06-19
      • 2011-01-10
      • 1970-01-01
      • 2022-11-12
      • 2013-03-16
      • 2012-08-07
      相关资源
      最近更新 更多