ajoslin / angular-mobile-nav

An angular navigation service for mobile applications
http://ajoslin.github.com/angular-mobile-nav
MIT License
785 stars 135 forks source link

about routing and $navigate.back() function #68

Open rainoxu opened 11 years ago

rainoxu commented 11 years ago

It has been really nice, this is not a serious problem: take your demo as an example, if a user visits http://ajoslin.github.io/angular-mobile-nav/#/two directly, the go-back button will not repond any action -- of course, the stack of history has no any data for his visiting. while the route config has all data deveoper set, so in the case, go-back button with the respond function ( $navigate.back() ) may action acording to the analysis of route config, how do u think this idea~

ajoslin commented 11 years ago

It sounds possible and useful! would you like to open a PR?

rainoxu commented 11 years ago

I have a personal project running during my spare time, maybe I could not send the PR within a short period, but I will try my best :)

cauli commented 10 years ago

My simple workaround on this

(Circa Line 213 of mobile-nav.js)

nav.back = function() {
      if (navHistory.length > 0) {
        var previous = navHistory[navHistory.length-1];

        $location.path(previous.path());
        nav.onRouteSuccess = function() {
          navHistory.pop();
          nav.next = previous;
          navigate(nav.next, nav.current, true);
        };
        return true;
      }
      else {
        nav.go('', false, true);
      }
      return false;
    };

Or: if there is no navHistory, nav.go to path '' using reverse animation.