How can we specify no route path in UI-Router?

0 votes
I'm having web page that contains all the links, but the problem is if the user attend to follow the unspecified path, How can i redirect to any custom link or display message to users?? Help me out please!!
6 days ago in Angular by kartik
• 1,910 points
12 views

1 answer to this question.

0 votes

hey @kartik,

In order to route to any custom URL or displaying message when user attend to certain unspecified route path,there are generally two ways to define in $stateProvider which is used to configure the UI-router.

The code is as follow:

var app= angular.module([$stateProvider , function($stateProvider){

      $stateProvider 

      .state('root', {

      url: '/',

     template:  '<strong> You are at root....</strong>

       }

     

     .state('noroute', {

      url: '*path',

     template:  '<strong> No Root Available...</strong>

       }

}]);

In order to redirect to existing route when no route found, the above code can be discard and include the $urlRouterProvider as follow:

var app= angular.module([$stateProvider , $urlRouterProvider, function($stateProvider, $urlRouterProvider){

      $stateProvider 

      .state('root', {

      url: '/',

     template:  '<strong> You are at root....</strong>

       }

     urlRouterProvider.otherwise('/');

}]);

answered 6 days ago by anonymous
• 3,230 points

Related Questions In Angular

0 votes
1 answer

How can we redirect to an existing route using ngRoute?

Routing is just another way of fixing some content ...READ MORE

answered Feb 6 in Angular by Niroj
• 3,230 points
19 views
0 votes
1 answer

How can we provide condition based on certain resolve result obtained in routing with resolve?

Hey,  Let me consider that you have some ...READ MORE

answered 6 days ago in Angular by Niroj
• 3,230 points
12 views
0 votes
1 answer

How can we achieve transclusion using link function and directive controller?

Hey, The Term Transclusion means unhidding the context ...READ MORE

answered Feb 5 in Angular by Niroj
• 3,230 points
23 views
0 votes
1 answer

How can we redirect to another page from existing page on clicking alert?

hii, It is really simple to redirect from ...READ MORE

answered Feb 6 in Angular by Niroj
• 3,230 points
16 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20 in Web Development by Niroj
• 3,230 points

edited Jan 21 by Niroj 29 views
+1 vote
1 answer

What is css box module?

Hey, All the element present in html follows ...READ MORE

answered Jan 20 in Web Development by Niroj
• 3,230 points

edited Jan 21 by Niroj 30 views
0 votes
1 answer

Explain the difference between visibility:hidden; and display:none?

hii, visibility:hidden; and display:none are totally different used ...READ MORE

answered Jan 20 in Web Development by Niroj
• 3,230 points
57 views
+1 vote
1 answer

How to access the Angularjs scope of a particular html element from our console?

Hello, You should follow the below steps:-- 1.Compile and ...READ MORE

answered Jan 21 in Web Development by Niroj
• 3,230 points

edited Jan 21 by Niroj 31 views
0 votes
1 answer

How do we work with UI-Router in AngularJS?

Hello @kartik,  As you know Ui-Router is more ...READ MORE

answered 6 days ago in Angular by Niroj
• 3,230 points
15 views
0 votes
1 answer

How can we achieve transclusion in AngularJs?

Hii,  In order to know what transclusion is ...READ MORE

answered Feb 5 in Angular by Niroj
• 3,230 points
15 views