-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Comments
Hi, thanks for filling this issue. |
Hi, if i don't set base, my router don't open first page '/' |
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. @Samuell1 For now, as a work around, you can manually call |
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. |
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! |
@cwang18 You can change |
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". |
You should use push to change url to |
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! |
@cwang18 that should work, if not then you missing htaccess or something i recommend to check vue router docs |
Thanks, I'll check those. |
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. |
Example:
https://jsfiddle.net/4c079nyf/10/
The text was updated successfully, but these errors were encountered: