我正在实施NgRoute,但是在angularjs教程中他们介绍了ui-route,我看了一些关于这条ui-route的视频教程,我发现它比mg路线更酷,更流畅,所以我去了ui-route我已经下载了js文件的github页面,我已经在脚本参考中添加它,并开始关注那里的指南,但我没有成功地让它工作,没有任何控制台错误,当我去网站网站只显示index.html !!
App.js
var app = angular.module("KhbyraApp", ['ui.router', 'ngCookies']);
app.config(function ($stateProvider, $urlRouteProvider, $httpProvider) {
$httpProvider.interceptors.push('httpInterceptor');
$urlRouteProvider.otherwise("/login");
$stateProvider
.state('login', {
url: "/login",
templateUrl: "app/views/login.html",
controller: "LoginController"
})
.state('register', {
url: "/register",
templateUrl: "app/views/register.html",
controller: "RegisterController"
})
.state('articles', {
url: "/articles",
templateUrl: "app/views/articles.html",
controller: "RegisterController"
});
的index.html
//<html>...
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/">Brand</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a ui-sref="articles">Home</a></li>
<li><a ui-sref="login">Login</a></li>
<li><a ui-sref="register">Register</a></li>
<li ng-if="isAuth" ng-click="LogOut()"><a href="/Logout">LogOut</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div ui-view></div>
//script....
</body>
答案 0 :(得分:0)
有一个工作(简化)plunk,表明此设置正常。
唯一的(但必不可少的)更改是&#39; $ urlRouteProvider&#39;的名称。应该是$ urlRouterProvider
(路由器而不是路由)
function( $stateProvider , $urlRouterProvider) {
$urlRouterProvider.otherwise("/login");