Currently, I have a setting based on the standard meanjs stack template, where I can have users who are logged into this state when they are "logged in" when I look at the URLs of the site. This is due to the fact that the user object is located in the Service, which is becoming publicly available.
However, this only works if I move from the base root, that is, from "/" and navigation only in my application.
If I manually enter a URL, such as '/ page1', it loses the user's global object, however, if I go to the root homepage and go to '/ page1' through the site. Then itβs fine, it sees the global user object in the Service object.
Therefore, I assume that this is due to a full refresh of the page, which loses its global significance, where it moves around the site, is not updated, so you save all your variables.
Some notes:
- I have included HTML5Mode using the '!' Prefix.
- I am using a UI-router
- I use a tag with '/'
- I have a rewrite rule for expressing that after loading all of my routes, I have one last route that takes all the "/ *" and sends back the root index.html file, as that means the stuff is angularjs.
I'm just wondering what are people doing here? Do they return standard cookies and local storage solutions? I am new to angular, so I assume there are libraries for this.
I just wanted to know which recommended way to handle this or what most do, so that I am properly aligned and angular, as I assume.
Update:
If I manually go to a different URL on my site through the address bar, I will lose my user state, however, if I manually go back to the root through the address bar, my user state will be seen again, so it's not just about losing state when updating window. So this seems to be due to code running on the root URL.
I have an express re-entry that manually enters URLs (due to the HTML5 layout mode), should first return index.html, since it contains AngularJs files, and then UI-Route takes over and directs it correctly.
So, I expected that any code in the root will be executed in any case, so it should be like navigating a site or entering an address bar. I have to skip something about angular that has this effect.
Update 2
That's right, so more research has led me to the following:
<script type="text/javascript"> var user = {{ user | json | safe }}; </script>
What server-side code is for index.html, I think it does not execute when I refresh the page on a new page using the URL manually.
Using hash-bang mode, it works, because in hash-bang mode even I type the URL in the browser, it does not cause an update, where, as in HTML5 mode, it is updated. So right now, the solution I can think of is using sessionStorage.
If there are no better alternatives?
Update 3:
It seems the best way to handle this when using HTML5Mode is that you just need to rewrite a few other things to the express server.