Using $routeProvider to redirect to routes outside of Angular

后端 未结 5 717
难免孤独
难免孤独 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:45

    Not sure what version of Angular JS the accepted answer was written on, but 'redirectTo' property takes in a function. So, why not do something simpler like this:

    $routeProvider.otherwise({
        redirectTo: function() {
            window.location = "/404.html";
        }
    });
    

    Obviously, you have to create your own 404.html. Or wherever your 404 page is.

提交回复
热议问题