-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refreshing the browser doesn't refresh the ui-router's state when doing nested states. #105
Comments
Can you provide this as a plnker or other working example? Navigating to http://angular-ui.github.io/ui-router/sample/#/contacts/1 and then manually changing the url to http://angular-ui.github.io/ui-router/sample/#/contacts works as expected in the sample app |
It'd be difficult to do in plunker do it's navigation. I'm using HTML5 urls if that might help. |
@CMCDragonkai -- if HTML5 mode is working for you would you please help me figure out how? I might be dense but I can't see them working... #116 |
@CMCDragonkai hard to say what's going on without seeing it in action... |
I bet this was the devil bug. |
Hi @CMCDragonkai, |
No I didn't. So it's left that way. |
I found this thread: EDIT:
If you also have a resolve function that might be making all the trouble, you could try wrapping it's contents in a timeout. That's what finally helped me. I used a timeout since I've noticed that the state resolve function was called before my app.run was called. I hope this helps you, or someone else that will see this thread. |
Hey @eggers, I think my problem was that some of the data I needed for the state's If you want to investigate some more, I suggest you use ui-router's state You can add some console logs on the stateChangeStart and the Good luck! I'll be glad to hear if you have any conclusions. On Tue, Feb 4, 2014 at 10:15 PM, eggers notifications@github.com wrote:
|
@jonathanadler I had a different issue. I hadn't put the leading |
I had what looked like a similar problem. My service (called within a nested state's resolve) was resolving a promise immediately with a null value, resulting in a blank screen. |
angular.module('app').run(['$state', '$stateParams',
function($state, $stateParams) {
//this solves page refresh and getting back to state
}]); This will solve the issue |
+1 @bikash1999's tip worked for me. |
while implementing "$locationProvider.html5Mode(true).hashPrefix('!');". When i refresh the page eg: url: localhost:8000 /project. |
@talhamaniar, this is most likely an issue with your backend setup, not with your angular code. If you directly navigate to e.g. http://localhost:8000/project (even if you do it via refresh), your browser will make a request to your backend for the path /project. But if this is only defined as a route/state in your angular code, your backend won't know how to deal with it -- you probably only serve your webapp on a url like http://localhost:8000/index.html. The solution is probably to get some sort of wildcard/catchall set up on your backend so that your webapp gets served on any URL that isn't a defined backend API call or some static resource. |
@talhamaniar I have a login screen and on this event i'm checking if user is Authenticated and performing the logic of handling
When I fire-up the app, its checks into the Authentication(I set a cookie value once the user is authenticated and set the value to cookie) and redirect the user to #/login if not authenticated. Once logged into the app can navigate through the links loading different views based on the route setup using ngRoute. ** The problem, when a user manually refresh the page, it redirect back to login and url changes to something like this before refresh : http://localhost/Index.html#/dashboard If I do a refresh again on the it gives me 404 not found. I'm using WebAPI for DB operations Please suggest, as I have a deadline and due for deployment to production and stuck with this issue |
@naveen2048 , it sounds like you are getting a mix of HTML5 and Hashbang behaviors, instead of just one or the other. (Go here and scroll down to the "Hashbang and HTML5 Modes" section to read more about this.) Do you have something like this in your code somewhere? There are 2 ways to fix your problem:
|
Thanks @zacronos as I understand the issue is when we setup the Html5 mode and do not have a hash (#) in the url. As per your comment if we are able to serve our webapp on any URL the browser might get , then this issue is fixed. But in Node how can we do that as with angular we just have a single file. Can anyone suggest me how can it be done with angular and node. |
@zeeshanjan82, sounds like you understand the problem. How to fix it will depend on how you have set up node to serve that single file, and whether you also have API calls or other URLs to handle. If you are using Express.js on the server, the easiest thing to do (which may not always be best) is to add a wildcard route ( |
thanks @zacronos I am using gulp and its plugins like watch and browsersync , in my case how can I do it. Do I need to include some middleware in my gulp file as a task? |
@zeeshanjan82, the question is how the file gets into your browser. Are you running a node backend server like Express.js to serve the file on something like |
@zacronos I have not yet created the backend yet, I have the frontend app which is an angularjs app and I have configured the gulp to have the app run on the url http://0.0.0.0:9000 |
@zeeshanjan82, then in that case gulp is acting as your backend server. I haven't used gulp that way, so I don't know what you need to do. But, since you will eventually have a real backend, anything you do now with gulp is just going to be a temporary fix. I would recommend that you ignore the problem for now, and revisit when you have started to build your backend. Or, you could go ahead and create a skeleton backend so you can fix this problem the "right" way instead of a temporary fix via gulp. |
thanks @zacronos I will surely follow your advice and will get back when I have implemented the backend. |
Are you using any sort of authentication and then checking for authorization on Sorry for the necro and if my terminology is incorrect; I'm new to AngularJS. |
@bikashsharmabks: Where do you add this code to avoid browser refresh taking to home page. angular.module('app').run(['$state', '$stateParams', |
I have the same problem when i refresh my page manually, and it's caused because of the resolve function from my state (i load some data from server). Did you managed to go pass this issue, without timeout? Thanks, |
gopikrishnahm, thank U very much good man! |
**@lifemixture @gopikrishnahm ** angular.module('app').run(['$state', '$stateParams', i tried to add but still its going to home page ..can you have any sample..? here is my config
}]);_ |
Hi @chetanganguly. I really stuck with this issue about half a year ago. Maybe this will help you |
this worked for me on local machine but not on server, Any hint please? $rootScope.$on('$stateChangeStart', function (event, toState) { |
Thanks , It worked for me |
In a situation like:
When you go into e.com/blog/123 and go back to e.com/blog by refreshing the browser or a location refresh, it doesn't change the state back to blog.posts. It does do it when I use the back button or hit on a link that changes the url, but a direct location refresh doesn't.
The text was updated successfully, but these errors were encountered: