0

For example, current URL is "http://localhost/#/mail". I do some actions, and I want to go to the next url:

$location.path("mail/inbox/3")

It works good. I'm in another controller with another URL. But when I click by "Back" browser button I hope to be returned to "mail" route, but instead of it I'm gone to "mail/inbox" route. Why? How can I fix it? Because it's incorrect for me. Thanks.

3
  • You sure you are not accidentally navigating to /inbox in between? Because what you are saying doesn't make sense Commented Nov 15, 2015 at 11:48
  • No. From "mail" to "mail/inbox/:id" without "mail/inbox" Commented Nov 15, 2015 at 11:51
  • could you provide a fiddle to reproduce this issue? i have a similar situation in my app and it works very well Commented Nov 15, 2015 at 14:54

1 Answer 1

1

When you fire up this baby:

$location.path("mail/inbox/3")

Do remember that it traversed through when('mail') and when('mail/inbox') to reach when('/mail/inbox/:number'). The route went from mail -> inbox -> #3. This is why when you hit back it goes to mail/inbox.

This is a messy situation to fix. ng-router or ui-router are good when thing are simple, but as application grows, bugs like your are unavoidable.

In my projects I disable the html5Mode with $locationProvider.html5Mode(false);, essentially disabling the back button. And add custom back buttons inside the App for user to navigate back.

This solution helps with:

  • User cant use back button at all, so he can't reach an unwanted state
  • Custom back buttons can be configured or hidden at times. Event code to preform differently on same view, based on current app state.
  • Hide the app internal URL from users to avoid the app being exploited for data the user is not supposed to see.

I hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.