Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base option is case sensitive #2154

Closed
billbill72 opened this issue Apr 12, 2018 · 8 comments
Closed

base option is case sensitive #2154

billbill72 opened this issue Apr 12, 2018 · 8 comments

Comments

@billbill72
Copy link

Version

2.8.1

Reproduction link

https://github.com/dev-shane/vue-router-bug-demo

Steps to reproduce

My app is served under /app/, then I have config /src/router/index.js as follow

export default new Router({
  mode: 'history',
  base: '/app',
  routes: [
    {
      path: '/',
      name: 'Index',
      redirect: {name: 'Home'}
    },
    {
      path: '/home',
      name: 'Home',
      component: Home
    },
    {
      path: '*',
      name: '/error',
      component: Error
    }
  ]
})

But I got this result
http://localhost:8080/app/home to /home
http://localhost:8080/app/Home to /home
http://localhost:8080/App/home to /error
http://localhost:8080/App/Home to /error

What is expected?

http://localhost:8080/app/home to /home
http://localhost:8080/app/Home to /home
http://localhost:8080/App/home to /home
http://localhost:8080/App/Home to /home

What is actually happening?

http://localhost:8080/app/home to /home
http://localhost:8080/app/Home to /home
http://localhost:8080/App/home to /error
http://localhost:8080/App/Home to /error

@emanuelmutschlechner
Copy link
Contributor

Can confirm, is this a bug?
https://codesandbox.io/s/rjv9oj6yoq

@posva
Copy link
Member

posva commented Apr 16, 2018

it shouldn't matter in most cases as the base is something that comes from outside your application but it would be better for it to be case-insensitive by default, like the rest of the url

@PikminGuts92
Copy link

I think I've found the issue. It appears to only affect router when in history mode. It's performing a case-sensitive comparison to remove the base path. Adding a couple toLowerCase() calls should fix it. If that's an acceptable solution I'm willing to put in a pull request and add some unit tests.

export function getLocation (base: string): string {
let path = window.location.pathname
if (base && path.indexOf(base) === 0) {
path = path.slice(base.length)
}
return (path || '/') + window.location.search + window.location.hash
}

@PikminGuts92
Copy link

Maybe even use a case-insensitive regex search instead. I'm not sure which is better performance wise.

@DinsmoreDesign
Copy link

DinsmoreDesign commented Nov 27, 2018

Just ran into this issue myself. In my case, I don't hit an error, because our app is hosted at /Locations on the server and a /Locations exists in the Router, but this is still really strange:

domain.com/Locations => Home component ("/")
domain.com/locations => Home/Locations component ( "/Locations")

Any other URL with the lowercase /locations will hit a 404. Any news on a fix being released for this?

@GHakopian
Copy link

Any news on this? is there any workaround?

@PikminGuts92
Copy link

@GHakopian @DinsmoreDesign Here's the snippet of code I had used for our workaround. Basically it just replaces the one vue-router function I referenced above.

// 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
  }
}

@ThatWionGuy
Copy link

Ran into this issue today using v3.1.6, this has been on Long term roadmap for almost a year and is marked as a high priority. It is one line of code to make urls case-insensitive as the web standards allow. Can we get an update on when this will be fixed? I have used the fix proposed by PikminGuts92 and it works but this is still a hack and would prefer a permanent fix for a production application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants