Angular redirect to homepage when updating

What is the best way to direct the user to the home page if they are updated from any other route (or indicate if you are using ui-router, like me).

For example, I want them to start on a page inventory. If they want to make changes, they are moved to the page edits, but if they refresh this page, they are redirected to the route inventory.

+4
source share
3 answers

I did not use ui-router, but in the ng route we can do it like

  • create a controller on top of your ng-view div
<body ng-controller="topController">
<div ng-view></div>
</body>
  • , topController

$location.path( "/" )

, "/" - , , $location

+6
window.onbeforeunload = function() 
{ 
  window.setTimeout(function () { window.location = 'homeURL'; }, 0); 
  window.onbeforeunload = null; 
}

0

Assume #/inventory- your route, useotherwise

$urlRouterProvider.otherwise("/inventory");

See URL Routing - $ urlRouterProvider

-1
source

Source: https://habr.com/ru/post/1540807/


All Articles