简体   繁体   English

UI路由不起作用且没有控制台错误

[英]UI-route doesn't work with no console errors

i was implementing NgRoute, but somewhere in angularjs tutorials they introduce ui-route, i watch some video tutorials about this ui-route, i find it cool and more fluent than the mg-route, so i went to ui-route github page where i've downloaded the js file, i have add it in scripts references, and start following there guide, but i haven't successfully get it to work, and without any console errors, when i go to site web it shows just the index.html !! 我正在实现NgRoute,但是在angularjs教程中的某些地方,他们介绍了ui-route,我看了一些有关此ui-route的视频教程,我发现它比mg-route更酷,更流畅,所以我去了ui-route github页面。我已经下载了js文件,已将其添加到脚本参考中,并开始按照该指南进行操作,但是我没有成功使其工作,并且没有任何控制台错误,当我转到网站时,它仅显示索引.html !!
App.js 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 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>

There is a working (simplified) plunk , showing that this setting is working. 有一个正在工作的(简化的) 插头 ,表明此设置正在工作。

The only (but essential) change is the name of the '$urlRouteProvider' which should be $ urlRouterProvider (the router instead of route) 唯一(但必不可少)的更改是“ $ urlRouteProvider”的名称,该名称应为$ urlRouterProvider (路由器而不是路由)

function( $stateProvider , $urlRouterProvider) {

  $urlRouterProvider.otherwise("/login");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM