question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to interrupt / override the ongoing routing?

See original GitHub issue

OpenUI5 version: 1.98.0

Under some circumstance, I would like to forward a user from the view «A» to the view «C» instead of the view «B». I’ve tried so far:

  1. attachRoutePatternMatched
  2. attachBeforeRouteMatched
  3. router.stop()
  4. changing a hash via the HashChanger
  5. sap.m.library.URLHelper.redirect(…)

attachRoutePatternMatched and attachBeforeRouteMatched work but I observe the undesired view «B» for a second and then I’m redirected to the view «C». router.stop() stops the navigation but then if I re-initialize it again within the same method, then I’m redirected the undesired view «B». Changing a hash via the HashChanger doesn’t help either. The only workaround that works for me is to use a hard redirect sap.m.library.URLHelper.redirect(…), that works correctly but I assume it leads to extra performance costs.

Is there any reliable and «friendly» approach to override /interrupt the ongoing routing, so user will not see the initially planned view but another one? I’m talking purely from the UX perspective, not the security-one.

Related topics:

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
flovogtcommented, Jan 14, 2022

Hi @pubmikeb , @jversignify points to a valid point. Overriding the HashChanger artefact would enable you to hook into the navigation process. But as @jversignify already points out, it is bad practice because the HashChanger artefact should not be changed by applications. We have discussed this requirement and thought about following future concept: You can attach your check function in the attachBeforeRouteMatched handler:

this.getOwnerComponent().getRouter().attachBeforeRouteMatched(this.checkAccess.bind(this));
checkAccess: function(oEvent) {
    if(!this.hasAccess()) {
       oEvent.preventDefault();
    }
   }

When the event is marked with preventDefault we would omit loading the target and the history would not contain the hash for this route. IMHO the downside of this solution is that the hasAccess method has to return synchronously the result. So, you can not perform any async backend calls here because the response of the backend call would come later than the navigation process. Whats your opinion on that?

2reactions
pubmikebcommented, Dec 23, 2021

What’s your opinion on that?

I also thought about this scenario and assumed that there should be 2 checks:

  • before the navigation, if a user tries to open a view from the side bar menu, here this approach can work out.
  • a user tries to open a view, which he has no permissions to, directly, via URL in address bar, then a permission check should be implemented somewhere in onBeforeRendering.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to stop router navigation based on some condition
routerState; this.router.navigateByUrl(currentRoute.snapshot.url, { skipLocationChange: true }); // this try to go to currentRoute.url but don't change the ...
Read more >
Re-routing & Rearranging Existing Routes on a PCB in Altium ...
Use the Shift+R shortcut to disable the Component re-route option in Interactive Routing page of the Preferences dialog. The current Component ...
Read more >
Cisco Webex Contact Center Setup and Administration Guide
If a Global Routing Override exists, it becomes the current routing strategy for the entry point, overriding any ... Click Save or Cancel....
Read more >
AngularJS cancel route change - YouTube
on("$routeChangeStart", function (event, next, current ) { if ... You can also cancel route change by handling $locationChangeStart event.
Read more >
Route updates and rerouting | Navigation SDK | Android
Route refresh to make sure the current route is still a viable route. Alternative routes to offer users alternative routes as available. Off-route...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found