I have embarked on creating my own SPA (Single Page Application) stack tool. Currently, I am contemplating the router mechanism for it - deliberating between using a hash (#) based router or exploring alternative options:
One option is to utilize the
window.history
API - similar to how Twitter has implemented pushState for their website (). It's intriguing why other popular frameworks like React and Angular don't opt for this approach and instead rely on the hash mechanism?Another possibility is to stick with the hash implementation but streamline the URL mapping by only utilizing one level of nested routes + parameters, such as:
#/posts
,#/post-new/
,#/post/<post-id>
,#/post-edit/<post-id>
,#/post-comments/<post-id>
By following this structure, there will be no need for complex regex patterns. Each route slug after the first slash will be simple and descriptive, while any parameter will be placed after the second slash (or multiple parameters can be handled with ?param1=X¶m2=Y
etc.). Are there any downsides to this approach?
EDIT:
To clarify some confusion - I am not interested in adopting existing solutions like Angular, React, Ember, etc. My intention is to develop a personalized tool tailored to my needs, rather than grappling with APIs that may not align with my vision.