camden_kid
camden_kid

Reputation: 12813

How to redirect page reload to a specific route?

How can I set up my AngularJS app to redirect to a specific route whenever a user clicks on page reload regardless of which ng-route the app is currently situated?

For example, if the user is at '/phones/:phoneId', when the user reloads the page the route will be set to '/phones'.

Upvotes: 0

Views: 154

Answers (1)

dimirc
dimirc

Reputation: 6605

You could change the $location from a run block:

Run blocks - get executed after the injector is created and are used to kickstart the application.

var myApp = angular.module('myApp');

myApp.run(function($location) {
    $location.path("/phones");
});

Upvotes: 1

Related Questions