angular / router

The Angular 1 Component Router
MIT License
665 stars 135 forks source link

rootRouter.navigate() when navigating is true #308

Open paulwalker opened 9 years ago

paulwalker commented 9 years ago

currently results in noop, which means i need to set up a watch on the navigating property. perhaps consider using a promise for the navigation events that navigate would then use?

paulwalker commented 9 years ago

here is the solution i am using for now in case someone may be interested:

  function forceNavigate($router, $rootScope) {
    return function(route) {
      if (!$router.navigating) return $router.navigate(route);
      var stopWatching = $rootScope.$watch(
        function() { return $router.navigating; },
        function() {
          stopWatching();
          $router.navigate(route); 
        });
    };
  }

  // app module .run
  function run($router, $rootScope) {
    $router.forceNavigate = forceNavigate($router, $rootScope);
  }

$router.forceNavigate(route);