Just wanted to share a new way for navigation of Anvil Apps that uses Browser Routing (commonly used in React apps). Turns out, it is also possible to do it in Anvil Apps (with some workarounds). And it has some great SEO benefits over Hash Routing.
Advantages
-
Better Crawling - Search Engines don’t prefer hash urls. Google has deprecated this method (although it still manages to crawl them). Bing also does not manage to fetch the new meta deta.
-
Control over Social Media meta tags - If you paste a link to
example.com/#!/Page1
, the preview in social medias will still show the title and description fromexample.com
. -
Better Support - Most of the popular sites like Facebook, Github, Linkedin, Netflix etc. use BrowserRouting. However, there is no example of any popular site using HashRouting.
Live Example
And here is a demo of how an individual article on my website appear
I will also be implementing this in my main website https://geeke.app once I fix the mess that I made previously for its navigation.
The Working
Browser routing uses History API. Javascript methods like pushState
allow changing the URL on the browser without actually going to that URL. So, it will say that we are at example.com/_/api/page
but we are still at example.com
actually.
But still one big problem - What to do when the user directly goes to example.com/_/api/page1
This is where the workaround comes. We create an HTTP endpoint handler for page1
in our Anvil Server. The server will return an HTML file containing the source code of our app but with modified meta tags for page1
The Dependency
So far, I don’t have any dependency that others can also use in their App. But I will be working on making one. I just wanted to share the idea with others first and get their opinions and feedback.