[英]Angular ui router redirect does't work
I'm using ui.router for routing in my Angular app. 我在Angular应用中使用ui.router进行路由。 This is a very simple app which have only 3 views: Home , FAQ and Contact.
这是一个非常简单的应用程序,只有3个视图:主页,常见问题和联系方式。 I have define 3 different states for each page and define their template url, but no navigation is working at all.
我为每个页面定义了3种不同的状态,并定义了它们的模板网址,但根本没有任何导航功能。 No view template is loaded into my index.html.
没有视图模板加载到我的index.html中。 I am attaching the following code
我附上以下代码
var app = angular.module('app', ['ui.router']) app.config(['$stateProvider,$urlRouterProvider',function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise('/home'); $stateProvider.state('home',{ url:'/home', templateUrl:'Home.html' }).state('contact',{ url:'/contact', templateUrl:'Contact.html' }).state('faq',{ url:'/faq', templateUrl:'FAQ.html' }) }]);
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script> <nav class="navbar navbar-inverse" role="navigation"> <div class="navbar-header"> <a class="navbar-brand" ui-sref="#">AngularUI Router </a> </div> <ul class="nav navbar-nav"> <li><a ui-sref="home">Home</a></li> <li><a ui-sref="faq">FAQ</a></li> <li><a ui-sref="contact">Contact</a></li> </ul> </nav> <div class="container"> <div ui-view></div> </div>
and my views are very simple one, for example Home.html 我的观点很简单,例如Home.html
<div>
Home Page!
</div>
Even I faced the same problem in the beginning.
甚至我一开始也面临同样的问题。 I solved it by running the application on a local server.
我通过在本地服务器上运行应用程序解决了该问题。
You can use brackets editor which has an inbuilt server. 您可以使用具有内置服务器的方括号编辑器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.