简体   繁体   中英

stop browsing when putting url from browser in angular.js

I have a project in which I have several sections. the user can only interact with my application through the internal navigation. but if the user writes something in the url, and reloads the page, I would like to be redirected to some state or failing to allow it. how can I do this?

I have this in my code.

angularRoutingApp.run(function($rootScope, $transitions)
{
  $transitions.onStart({ }, trans => {    })

and in my real project I do validation depending on the state I receive, but in this case I do not know how to detect when navigating directly when writing the url from the browser navigation bar.

Though I have less experience in Angular JS (only with typescript), my opinion here: You can use Router(from '@angular/router') to identify the new query param value. If this param is not what you intend it to be or if you want to redirect it to some other page, you may use router.navigate and update the query params.

router.navigate([newTab.url], { queryParams: 'merge' });

The newTab.url can be the error page you want to navigate to. PS: I hope I understood your problem right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM