Vue-router: [Feature request] Case Insensitive match

Created on 14 Jan 2016  路  13Comments  路  Source: vuejs/vue-router

Would be nice to see this feature to match routes without being case sensitive, can be global or attached to a map, example:

router.map({
        '/abc': {
            caseInsensitive: true,
            component: require('./components/abc.vue')
        },
        '/def': {
            caseInsensitive: false, // default to false
            component: require('./components/def.vue')
        }
})
1.x feature feature request

Most helpful comment

The default should definitely be case sensitive, because the request part of URL is case sensitive (as opposed to the domain part, which is case insensitive).
A use case for case sensitivity is string identifiers, e.g goo.gl/5yFJll.

All 13 comments

What are use cases you think?

Angular has this feature, it's just to avoid to do additional route redirections on the server-side/back-end & manage all your routes in your front-end application for this case :wink:

I think you should be able to use redirect({...}) for this, no? But yeah, your proposed solution is shorter.

router.redirect({...}) could be the solution if the first parameter could handle a regular expression (eg: /abc/ig) which is not the case at the moment

Is this still not possible?

@jrenton The use case seems unclear to me. X has Y feature is not a valid use case unfortunately

@posva: I think case-insensitivity should be the default behaviour (because normal URLs are, too). vue-router 2.0 behaves this way as well. I think this could also be considered a bug in a way.

If we do this, I don't think we should add an option to make routes case-sensitive again - it's a counter-intuitive behaviour IMHO.

But why would you have a link that is supposed to be lower case with upper case characters in the first place?

because users can type anything they want into their browser.

but for vue-router (1.0), these two URLs are not the same:
/profile/me
/profile/Me

...and that would be unexpected behaviour because if this was a server-side request, the two would be handled the same.

because normal URLs are, too

@LinusBorg Just a side note, urls aren't case insensitive by default, but is enabled to be, by many websites/webservers. see http://webmasters.stackexchange.com/a/69713

I agree with @posva because normal people wouldn't bother typing upper case characters if they just want to visit a website... So it's fine to make urls case sensitive by default, as long as you don't provide links that contain upper case characters.
But on the other hand enabling case insensitivity can be a nice-to-have option, (as long as someone would like to implement it).

Thanks for the discussion guys. I'd like to add why this is a pain for me personally and why I think case sensitivity should be an opt-in.

In .NET MVC applications, the default behavior is to have routes like: /Foo/Bar. There is an option to opt out of this, and strictly use all lowercase, but our site is so large and there are many concerns with making a broad change to make it all lowercase.

The fact that Vue router enforces this strict behavior makes it very difficult to deal with and have to be concerned about previous URLs/links/emails that already exist (because of changing an existing URL to a vue app).

I would agree that making all lowercase URLs and having case sensitivity is probably a best practice, but a framework should not force you into it, and if so, at minimum should give you an option to opt out of it.

@jrenton Thanks for your feedback!
@fnlctrl I'm not sure we can introduce the default behaviour to differ from actual behaviour. That would be a breaking but at the same time it can be seen as a bug: I don't see why would someone have different routes with the same name, just differently cased.

We can also provide two levels of customization:

  • In router creation an option like caseSensitiveRoutes that is false by default
  • At route declaration with an option like caseSensitive that also defaults to false

The default should definitely be case sensitive, because the request part of URL is case sensitive (as opposed to the domain part, which is case insensitive).
A use case for case sensitivity is string identifiers, e.g goo.gl/5yFJll.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Juli0GT picture Juli0GT  路  29Comments

rhyek picture rhyek  路  34Comments

sonic182 picture sonic182  路  32Comments

jwahdatehagh picture jwahdatehagh  路  29Comments

alekbarszczewski picture alekbarszczewski  路  39Comments