Skip to content

With routerBase being "/a/", landing on "/app" is incorrectly redirected to "/a/pp" #3555

Closed
@eyedean

Description

@eyedean

Version

3.5.1

Reproduction link

https://jsfiddle.net/eyedean/4qcd9kgy/21/

Steps to reproduce

It's hard to reproduce in the jsfiddle and such. That's what I mentioned in the TODO section of the link above.

Actual reproduction

  • Let's say I have a Vue App with HTML5 History Router and RouterBase being /a/.
  • If I land on www.mydomain.com/bpp/, VueRouter properly shows the App's 404 (catch on /*/ in routes) page.
  • However if I land on www.mydomain.com/app, then Vue Router redirects it to www.mydomain.com/a/pp which is not expected. (Assume /a/pp is an existing page, and not the intended target of /app)

What is expected?

show 404 on /app, just like /bpp.

What is actually happening?

redirects it to /a/pp, which can be a different existing page.


I tried to debug this on my own. Here is what I found.

When I set VueRouterBase to /a/ (with trailing slash, as advised in the documentation), router.options.base is properly /a/, but the history.base is going through normalizeBase and becomes /a. That's why /app gets sliced (via

if (base && path.toLowerCase().indexOf(base.toLowerCase()) === 0) {
path = path.slice(base.length)
}
) and becomes path: "/pp".

I also tried getting around this by setting routerbase to /a// (double trailing slash). It stopped the /app => /a/pp redirect, successfully, but then all my links were ugly! (e.g. <router-link to="/login"> would produce www.mydomain.com/a//login with double slash in between.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions