AngularJS否则路由无法正常工作?

The*_*ner 1 angularjs

我的AngularJS重定向看起来像这样:

// create the module and name it asApp
var asApp = angular.module('asApp', ['ngRoute']);

// configure our routes
asApp.config(['$routeProvider', '$httpProvider', '$locationProvider', function($routeProvider, $httpProvider, $locationProvider) {
    $routeProvider

    // route for the home page
    .when('/', {
        title: 'Home of PeppyBurro – Radical Spanish learning tips and tricks for the adventurous learner',
        templateUrl : 'pages/home.html',
        controller  : 'mainController'
    })

    // route for the about page
    .when('/about', {
        title: 'About PeppyBurro – Radical Spanish learning tips and tricks for the adventurous learner',
        templateUrl : 'pages/about.html',
        controller  : 'mainController'
    })

    // route for the 404 page not found error
    .when('/notfound', {
        title: 'Page not found',
        templateUrl : 'pages/404.html',
        controller  : 'mainController'
    })

    .otherwise('/notfound', {
        title: 'Page not found',
        templateUrl : 'pages/404.html',
        controller  : 'mainController'
    })
}]);
Run Code Online (Sandbox Code Playgroud)

我需要的是,当在URL中输入未定义的slug时,脚本将我路由到404.html.因此,如果用户输入mysite.com/#/about,则应该向他显示该about.html页面.这个位工作正常.但是,当用户输入时mysite.com/#/abc,它应该向404.html我显示我在我.otherwise.when('/notfound')指令中定义的页面.但是虽然.when('/notfound')位工作正常,但.otherwise不是.有什么我想念的吗?

die*_*uhd 5

我认为你应该修改为:

 .otherwise({
      redirectTo: '/notfound'
  }
Run Code Online (Sandbox Code Playgroud)

参考这里