-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Allow using base
option with hash under history mode
#1349
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
Conversation
I'm a bit confused - what is the use case for this? Why would someone use a base with |
@fnlctrl Isn't it better to make the electron/nw app start a local server and visit that instead? I remember there was a way of setting up a dynamic port for that |
@yyx990803 Sorry I didn't make my use case clear 😅 Let me try again.. 1. Why base with hash?To make history mode work under 1.1. Why doesn't history mode work under
|
This reverts commit f5db5b8.
I merged it but afterwards I don't think I fully understood the patch, so I reverted it for now. Does this feature require the base to be hard-coded to the file path? |
Yes, this is only meaningful if base is hard-coded to the file path ( |
What's the primary reason for not just using hash mode? For |
Yes, the primary reason was "scrollBehavior", with other benefits of being able to use history api (e.g. using history.go). |
I think it's a valid use case, but using base with hash sounds like a hack. Technically I think we should improve |
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
I'm not sure if using '#' inside base is a valid usage, though it currently works (in history mode, with an issue fixed by this PR), so I don't know whether it's a fix or a feature...
So the use case is:
file://
scheme.scrollBehavior
can be used. (to deliver a native-like experience without manually adding code to track/restore scroll position)It may seem crazy, but let me explain:
Normally history mode won't work under
file://
schemee.g.
file://path/to/index.html
+ history mode + route '/foo' =file://path/to/index.html/foo
, 404!But if we add a hash inside
base
, almost everything works (history API, popstate, etc).e.g.
file://path/to/index.html
, we usebase: 'file://path/to/index.html#'
(location.pathname + '#'
) and trick the browser into thinking it's a hash route.The only issue is: when using
router.back()
, the route gets parsed as hash, resulting in a non-matched route. (due to the current way vue-router parses location insidegetLocation
using location.hash)e.g.
file://path/to/index.html#/foo
=>file://path/to/index.html#/bar
, then userouter.back()
(or history.go(-1)), the router now parses the location as{path: '/path/to/index.html', hash: '#/foo'}
This can be considered some kind of a
semi-hash
mode that utilizes history API while using a hash route.This way we allow hybrid apps using
file://
scheme to enjoy history mode without being limited to hash mode.//
Side notes:
popstate
andhashchange
are both fired when navigating.