-1

Basically, I want to redirect the user to the homepage [''] when the user refreshes the current route or just do pull-refresh on the mobile device. Does anyone know how to make it easily in the Angular app? I was trying to implement the window beforeunload event but it's not working properly.

W12
  • 57
  • 7
  • 1
    What you have done so far? share your piece of code here as well. – Hardik Solanki Jan 09 '23 at 12:27
  • You could try checking if the page has been called by a refresh during the ngOnInit and if it did, either change the route or the href directly. See this post: https://stackoverflow.com/questions/5004978/check-if-page-gets-reloaded-or-refreshed-in-javascript – Zerox Jan 09 '23 at 14:40

1 Answers1

-1

You can route to that component on ngOnInit in your app.component that how every time when user refresh the page it will redirect to your desired component but before routing to that page check your component condition if current route is from that component you wants to route.

`export class AppComponent { constructor(private router: Router) {}

ngOnInit() { if(your condition) this.router.navigate(['']) } }`