$ routeProvider不路由

时间:2017-11-21 18:02:11

标签: angularjs route-provider

我正在尝试使用$ routeprovider重定向网址

$routeProvider.when('/', {
            templateUrl : 'scripts/login/login.tpl.html',
            controller : 'LoginCtrl'
        });
        $routeProvider. when('/sample', {
      templateUrl: 'sample.html'
    });
        $routeProvider.otherwise({
            redirectTo : '404.html'
        });

以下是加载应用程序的网址

http://localhost:8080/orion-web/app/

当我尝试将“sample”一词附加到网址时 即

http://localhost:8080/orion-web/app/sample

我收到404错误,这不是来自$ routeprovider的404.html。这是tomcats 404资源未找到页面

3 个答案:

答案 0 :(得分:0)

您是否为网页设置了基本网址?

应该是< base href =“/ orion-web / app /”>在index.html的标题部分

答案 1 :(得分:0)

在第二个$ routeprovider中尝试删除/

$routeProvider. when('sample', {
  templateUrl: 'sample.html'
});

答案 2 :(得分:-1)

  $routeProvider
   .when('/', {
            templateUrl : 'scripts/login/login.tpl.html',
            controller : 'LoginCtrl'
        })
    . when('/sample', {
      templateUrl: 'sample.html'
    })
    .otherwise({
            templateUrl: '404.html'
        });

使用此代码

相关问题