Skip to content

In abstract mode, router doesn't load root path '/' on initial load. #729

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

Closed
Samuell1 opened this issue Oct 6, 2016 · 12 comments
Closed

Comments

@Samuell1
Copy link

Samuell1 commented Oct 6, 2016

Example:
https://jsfiddle.net/4c079nyf/10/

@fnlctrl
Copy link
Member

fnlctrl commented Oct 7, 2016

Hi, thanks for filling this issue.
May I ask why are you using base in abstract mode? Since in abstract mode, urls don't matter, using base shouldn't give any noticeable change

@Samuell1
Copy link
Author

Samuell1 commented Oct 7, 2016

Hi, if i don't set base, my router don't open first page '/'

@fnlctrl
Copy link
Member

fnlctrl commented Oct 7, 2016

In abstract mode, setting base won't redirect to '/' either, as shown in your original fiddle.

So I think this is about abstract mode not directing to '/' on initial load.
As a fallback mode, abstract mode is supposed preserve the behavior of history/hash mode of directing to '/' on load, so I'm marking this as a bug.

@Samuell1 For now, as a work around, you can manually call router.replace('/'), see example below.
https://jsfiddle.net/qpnaokhf/

@fnlctrl fnlctrl changed the title Router construct option "base" doesnt redirect in abstract mode In abstract mode, router doesn't load root path '/' on initial load. Oct 7, 2016
@yyx990803
Copy link
Member

yyx990803 commented Oct 8, 2016

This is intended - in the browser, the user may visit the non-root URL on initial load, so the root view may not get rendered at all. In abstract mode, when the application boots it will be in a "nowhere" state until you explicitly tell the router where it is. This gives you a chance to render a non-root URL as your initial view, instead of rendering the root view and then triggering a navigation + re-render.

@cwang18
Copy link

cwang18 commented Mar 1, 2019

How to render a non-root URL as the initial view?

Take the code in https://jsfiddle.net/qpnaokhf/, if the original URL is "/bar", how to show component Bar accordingly?

Many thanks!

@Samuell1
Copy link
Author

Samuell1 commented Mar 1, 2019

@cwang18 You can change / in replace function for what you need

@cwang18
Copy link

cwang18 commented Mar 1, 2019

Thanks!

However, how to tell what's in the replace function? When URL is root, should use replace("/"), but when URL is root + "/bar", should use replace("/bar").

To my test, $route.path always returned "/", no matter initial URL is root or root + "/bar".

@Samuell1
Copy link
Author

Samuell1 commented Mar 1, 2019

You should use push to change url to /bar

@cwang18
Copy link

cwang18 commented Mar 1, 2019

Let me rephrase my question:

Take the code of https://jsfiddle.net/qpnaokhf/. It hard coded: router.replace('/'), so the initial view is always Foo. This is correct if hitting URL http://root/.

But if hitting URL http://root/bar, I would like to show Bar.

What's the way to dynamically push the correct route based on the URL?

Thanks!

@Samuell1
Copy link
Author

Samuell1 commented Mar 1, 2019

@cwang18 that should work, if not then you missing htaccess or something i recommend to check vue router docs

@cwang18
Copy link

cwang18 commented Mar 1, 2019

Thanks, I'll check those.

@fayt81
Copy link

fayt81 commented Oct 1, 2019

I have the same problem of @cwang18. I have the router in abstract mode and I would like to always start from '/' unless when the URL has some specific paths (e.g., "/test"), which should lead to a specific component. I set the router to handle the component at that path, but the app always starts from '/' and $route.path is always '/', no matter what there is in the URL. @cwang18, have you manage to get it work? I think I have followed @Samuell1 instruction, but with no success.

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

No branches or pull requests

6 participants