Routing in a single page application with a different home page

I have a one-page application - this means that everything on the server is redirected to a single index.html file, which does the hard work and routing using the HTML5 api ( ) history.

Now I want to add a new landing page to the side - call her landing.html , and I want clients to get to landing.html first when they access / and index.html if they access any other route.

Now IE9 does not support the HTML5 History API, so using hash URLs like /books/authors in it becomes /#!/books/authors . Since the hash section of the URL is not sent to the server , since the server belongs to them, all paths are / , which means that I cannot go to landing.html or index.html based on this logic.

I thought about redirecting URLs with / to landing.html , finding #! on the client by adding a cookie on the server (or client) called notReallyHomePage and redirecting to the correct page based on the cookie on the server. This is a really hacky and not very good solution.

What would be the right way to handle routing in this case?

My backend is in ASP.NET MVC, but I don't think this is relevant to the issue

+5
source share
1 answer

Hmmmmm ... What is the contents of landing.html? On his behalf, I assume that this is a fairly simple page.

Could you include its contents in index.html and hide / show it according to the "first time" logic? Or if landing.html is some kind of weird page created by your marketing or something else, then put it in an iframe that hides / shows by the same logic.

(obviously, when you show landing.html, then you hide index.html)

0
source

Source: https://habr.com/ru/post/1237087/


All Articles