Angular routeProvider - 无法在超出root的情况下使用url param进行路由

时间:2017-03-16 14:01:57

标签: javascript angularjs ngroute url-parameters

我的路线大部分工作正常。调用/:id非常有效,它将从API加载正确的文档。但是,我刚添加了一个新的密码重置路径,我添加了/reset/:id。这会抛出一个注入器错误,它会在我的js文件中显示HTML,开发人员控制台显示它也试图从不正确的路径加载js文件。

我在想我错误配置了一些东西。其他每条路径都能正常运作。

Core.js

angular.module("myApp", [ "ngRoute", 'wikiController', 'wikiServices' ])
.config(function($locationProvider) {
    $locationProvider.html5Mode({
        enabled : true,
        requireBase : false
    });
})
.config(function($routeProvider) {
    $routeProvider
    .when("/", {
        templateUrl : "main.html",
        controller : "mainController",
        controllerAs : "app"
    })
    .when("/forgot", {
        templateUrl : "forgot.html",
        controller : "forgotController",
        controllerAs : "app"
    })
    .when("/reset/:token", {
        templateUrl : "reset.html",
        controller : "resetController",
        controllerAs : "app"
    })
    .when("/:id", {
        templateUrl : "module.html",
        controller : "moduleController",
        controllerAs : "app"
    })
    .otherwise({
        redirectTo : 'main.html'
    })
})

的index.html

<!-- index.html -->
<!doctype html>
<!-- ASSIGN OUR ANGULAR MODULE -->
<html ng-app="myApp">
<head>
<!-- META -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Optimize mobile viewport -->
<title>Anima Learning - Wiki</title>
<!-- SCROLLS -->
<link rel="stylesheet"
    href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="css/main.css">
<!-- load bootstrap -->
<style>
html {
    overflow-y: scroll;
}

body {
    padding-top: 50px;
}
</style>
<!-- SPELLS -->
<script
    src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script
    src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<script src="js/controllers/index.js"></script>
<script src="js/services/index.js"></script>
<script src="js/core.js"></script>
</head>
<!-- SET THE CONTROLLER AND GET ALL TODOS -->
<body>
    <div class="container">
        <div ng-view></div>
    </div>
</body>
</html>

0 个答案:

没有答案