I’m having issues with the router when entering the address in the browser address bar.
Using ‘pushState: true’, it correctly displays the path/address in the browser as I navigate through the app (e.g. ‘http://localhost:8081/#!/about/’).
However, if I type or change ‘about’ to ‘form’ and press enter, it does nothing. Interestingly, if I press the browser refresh button (after pressing enter) the page navigates to the form page correctly.
How do I make it navigate to the page I want when I enter any correct URL and press the enter key?
I found a solution
in you main view’s onViewInit event handler, check whether the url pathname equal index(’/’), if not navigate to url.pathname and call router.refreshPage()
<View
id="view-home"
browserHistory={true}
browserHistorySeparator=""
main
onViewInit={viewInit}
/>
const viewInit = (view) => {
const url = new URL(window.location);
if (url.pathname.toLocaleLowerCase() !== "/") {
console.log(`navigate to ${url.pathname} on init`);
view.router.navigate(url.pathname);
view.router.refreshPage();
}
This seems to work. I tested it with URL parameters too. However, now, coincidence or not, my cordova app won’t run on the Android emulator. It freezes on the splash image.
That got me to a 404 page on the cordova Android emulator. To fix that, I made the browserHistory view configuration suggested above depend on the device type: