I’m attempting to get a child route to load properly nested on initial page load in a PWA. I have the following routes (below) and want an initial page load to /about/ to be able to go ‘back’ and have it go to the root view. This works where the app does animate the view away to show the root view underneath, but the browser then goes back itself to the previous webpage I had open. I do have :push-state="true" enabled on my main view.
Я не совсем понял, в чем проблема? При создании view указываете url : ‘/’, затем в методе init() роутер загружает страницу /about/, теперь она будет второй в истории.
Which is happening, but a single click of the ‘back’ button not only takes the app back to the root view, but it also triggers the browser to bo back in history which takes it to my previous website.
Anyone else’s input on this would be great. I simply want to be able to open a route from a direct URL and have the necessary routes automatically added to the navigation stack.
This is default browser behavior and can’t be affected if user presses Browser’s back button. On your UI’s back button, you can do the following:
// go back to home page without affecting history
v.router.back('/', { force: true, pushState: false });
// replace browser url to home page
window.history.replaceState({}, '', '/')
How about hooking to on a.back click and depending on wethere there is something in history i either preventDefault or not? Could that theoretically work?