Describe the bug
When BeamGuard is applied, BeamerDelegate configuration is left incorrect if BeamGuard redirects on the same page we are currently on. A visible result of this is wrong URL in the browser address field in the web application.
Beamer version: 1.5.5
To Reproduce
Let's assume that there is an application that have two screens, auth and main. The navigation between them is set through BeamerDelegate with a single location that handles two pages with the following routes: /auth and /main. To forbid navigation to /auth after user had authorized, BeamGuard is added.
The simplified version of it looks like this:
and then the method exits in the middle without restoring the configuration
// run guards on _beamLocationCandidate
final context = _context;
if (context != null) {
final didApply = _runGuards(context, _beamLocationCandidate);
_didRunGuards = true;
if (didApply) {
return;
} else {
// TODO revert configuration if guard just blocked navigation
}
}
If _runGuards method redirects to another page, this issue doesn't happen, because update is called again and updates the configuration. For example, if beamToNamed is set, update method is called either from beamToReplacementNamed or from beamToNamed. But if it detects that redirect is the current route, it exits.
if (beamToNamed != null) {
final redirectNamed = beamToNamed!(origin, target);
if (redirectNamed == target.state.routeInformation.location) {
// just block if this will produce an immediate infinite loop
return true;
}
if (redirectNamed == origin.state.routeInformation.location) {
// just block if redirect is the current route
return true;
}
if (replaceCurrentStack) {
delegate.beamToReplacementNamed(redirectNamed);
} else {
delegate.beamToNamed(redirectNamed);
}
return true;
}
Describe the bug When BeamGuard is applied, BeamerDelegate configuration is left incorrect if BeamGuard redirects on the same page we are currently on. A visible result of this is wrong URL in the browser address field in the web application.
Beamer version: 1.5.5
To Reproduce Let's assume that there is an application that have two screens, auth and main. The navigation between them is set through BeamerDelegate with a single location that handles two pages with the following routes: /auth and /main. To forbid navigation to /auth after user had authorized, BeamGuard is added. The simplified version of it looks like this:
So basically it redirects back to /main. The steps to reproduce are:
Expected behavior the URL in the browser shows /main
As I can see in the code, this happens because configuration is changed before applying BeamGuards in the update method:
and then the method exits in the middle without restoring the configuration
If _runGuards method redirects to another page, this issue doesn't happen, because update is called again and updates the configuration. For example, if beamToNamed is set, update method is called either from beamToReplacementNamed or from beamToNamed. But if it detects that redirect is the current route, it exits.