Using $routeProvider to redirect to routes outside of Angular

后端 未结 5 715
难免孤独
难免孤独 2020-12-05 04:34

I\'ve written part of a web application in Angular. To ensure that all routes are covered, I wanted to add a redirectTo property to the $routeProvider

5条回答
  •  青春惊慌失措
    2020-12-05 04:43

    You could do something like this:

    $routeProvider.when('/404', {
        controller: ['$location', function($location){
            $location.replace('/');
        }]
    }).otherwise({
        redirectTo: '/404'
    });
    

    It is essentially the same thing, only it uses less code.

提交回复
热议问题