I’m facing the same problem. They have documented it without examples which is very much inconvenient for beginners like me. I understood that it should be used with pushStateRoot. But where that should be defined? In routes.js with views for that exact route information? All such examples are missing. Can someone please comment and give an example? Android back button makes the app exit.
Hi @Ezra_Siton , Thanks a lot for the detailed instructions and the links for understanding the router concept. I will surely go through it and try to understand.
I’m new to web development and don’t know Javascript yet. I am using framework7 core. I couldn’t apply the same technique here as the templates were a bit different and I’m using kitchen sink example for my app and just customising few things in there. I will learn routing and get back to you if I get into any doubt, Thanks buddy!
Hi Ezra,
Yes. Thank you.
The problem was with an additional view statement which was not defined. After going through the complete code, I got to know that this statement was additional and not required. After removing that, it worked fine.
Thanks a lot for your help and follow-up.
@joelz, does this work for you if you go to the route directly? For some reason, whenever I use browserHistorySeparator, it only works if I go to the route with the app. However, if I comment it out and use /#!, it works perfectly to access the route directly.
This is because the # is an url Fragment and as such its not fetched from the server as a real directory/file, and wont cause the 404 error.
So for that case you need to configure your server to rewrite and route to the index.html
You can use this .htaccess:
RewriteEngine On
# Redirection of requests to index.html
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^.*$ - [NC,L]
# Redirect all non-file routes to index.html
RewriteRule ^(?!.*\.).*$ index.html [NC,L]
You can put this .htaccess file in your public folder, so it is copied during build
For this to work, it is also important to not use relative paths otherwise when going to url like “/home/2” its going to fetch for example a “assets/vendor.js” files from that base!
For that if you use vue for example you can set the build to generate semi relative paths that starts with the “/” instead of “” , so do they are relative to the domain. For a vite(VUE) config for example change the base url to “/”. For webpack and other have their way