Brk
Brk

Reputation: 1297

Angular ui router redirect does't work

I'm using ui.router for routing in my Angular app. This is a very simple app which have only 3 views: Home , FAQ and Contact. I have define 3 different states for each page and define their template url, but no navigation is working at all. No view template is loaded into my 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

<div>
    Home Page!
</div>

Upvotes: 0

Views: 78

Answers (2)

Daniel
Daniel

Reputation: 6491

You forgot to close your dependencies quotes:

Just change

app.config(['$stateProvider,$urlRouterProvider',

To

app.config(['$stateProvider','$urlRouterProvider',

Plunker

Upvotes: 2

Punith Mithra
Punith Mithra

Reputation: 628

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.

Upvotes: 0

Related Questions