How can we redirect to an existing route using ngRoute

0 votes
Can anyone provide the generic syntax of redirecting to another page from an existing web page??
Feb 6, 2020 in Angular by kartik
• 37,530 points
931 views

1 answer to this question.

0 votes

Routing is just another way of fixing some content dynamically as part of your application.It is a key part of all websites and web applications in one way or another and ng-route is a way to achieve routing in client side of AngularJS.

If you want to route to another page then the generic syntax.

var app= angular.module( 'app', [ngRoute]);
app.config([ '$routeProvider', function($routeProvider){
        $routeProvider.when( '/first-msg' ,{
        templateURl :msg.htm,
        controller:message1
})
}]);

And, if you want to redirect from the existing route then add redirect attribute having the following syntax:

var app= angular.module( 'app', [ngRoute]);
app.config([ '$routeProvider', function($routeProvider){
        $routeProvider.when( '/first-msg' ,{
        templateURl :msg.htm,
        controller:message1

        .when( '/second-msg' ,{
         redirectTo:"/first-msg"
})
}]);

answered Feb 6, 2020 by Niroj
• 82,780 points

Related Questions In Angular

0 votes
1 answer

How can we reload a page after requesting the same get parameter using AngularJS?

hey kartik, The reason for this is that ...READ MORE

answered Feb 10, 2020 in Angular by Niroj
• 82,780 points
9,267 views
0 votes
1 answer

How can we go back to previous page after having some error on request made through current page ?

$route is used for deep-linking URLs to controllers ...READ MORE

answered Feb 11, 2020 in Angular by Niroj
• 82,780 points
171 views
0 votes
1 answer

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

hey @kartik, In order to route to any ...READ MORE

answered Feb 11, 2020 in Angular by anonymous
• 82,780 points
185 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, 2020 in Angular by Niroj
• 82,780 points
115 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, 2020 in Web Development by Niroj
• 82,780 points

edited Jan 21, 2020 by Niroj 257 views
+1 vote
1 answer

What is css box module?

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

answered Jan 20, 2020 in Web Development by Niroj
• 82,780 points

edited Jan 21, 2020 by Niroj 286 views
0 votes
3 answers

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

display:none means that the tag in question will ...READ MORE

answered Dec 13, 2020 in Web Development by Gitika
• 65,930 points
48,179 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, 2020 in Web Development by Niroj
• 82,780 points

edited Jan 21, 2020 by Niroj 214 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, 2020 in Angular by Niroj
• 82,780 points
1,929 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, 2020 in Angular by Niroj
• 82,780 points
289 views