Cesar Vega
Cesar Vega

Reputation: 455

AngularJS redirectTo is no finding the right path

I have a configuration for my $routeprovider that when I change the redirectTo: function() {'/dasboard'} to redirectTo: function() {'/home'}, it goes to the otherwise route, .otherwise({redirectTo: '/404'});.

The home.html and the dashboard.html are at the same level folder, and I'm using this Template. What could be the problem?

app.config([
'$routeProvider', function($routeProvider) {

  return $routeProvider

   .when('/', {

                redirectTo: function() {return '/home'} /*before 'return /dasboard'*/
    })

   .when('/login', {

               templateUrl: '/views/pages/signin.html'
  })

  .when('/signup', {

               templateUrl: '/views/signup.html'
  })

  .when('/dashboard', {

                templateUrl: 'views/dashboard.html'
  })

  .otherwise({

    redirectTo: '/404'
  });
}

]);

Upvotes: 0

Views: 817

Answers (1)

Brian Lewis
Brian Lewis

Reputation: 5729

The problem you are having, is that you are redirecting to a route that does not exist. Then you are attempting to fallback on another route that is also undefined.

You need to declare the "home" and "404" routes.

.when('/home', {
    templateUrl: 'views/home.html'
})
.when('/404', {
    templateUrl: 'views/404.html'
})

The route that you are redirecting to needs to have a template. The route you are redirecting from does not.

You can read more about the $routeProvider here: https://docs.angularjs.org/api/ngRoute/provider/$routeProvider

Upvotes: 1

Related Questions