beamer icon indicating copy to clipboard operation
beamer copied to clipboard

BeamGuard wrongly blocks beamTo

Open schultek opened this issue 2 years ago • 2 comments

Describe the bug

I have a bug where I use a BeamGuard to redirect from one BeamLocation to another. The issue is that is never updates the pages and never builds the new BeamLocation.

After digging around, I found the responsible code lines:

package/lib/src/beam_guard.dart#L132-L136

The issue is that my redirected BeamLocations does not change the url location, but instead displays a different page for the same url.

I see why the specified lines are there but for me this does not work. Maybe the if block could also check whether the runtimeType of both BeamLocations are different.

If there is some other way that allows a BeamGuard to redirect to a BeamLocation without changing the url let me know.

Beamer version: 1.4.1

schultek avatar May 25 '22 16:05 schultek

Hey old friend @schultek :slightly_smiling_face:

I see what you mean... This is an interesting problem that should definitely allow more customization, e.g. that you can optionally customize what should BeamGuard treat as equal.

I'm planning to rework the guards for v2 so will assign this there. I plan to start working heavily on v2 next week.

slovnicki avatar May 26 '22 21:05 slovnicki

I might have a related problem. I have two nested beamers. The top one has two guards: one that redirects unauth users to /signup and one that redirects users to /home.

The /home has another beamer, this beamer should also show a page when the url is /home:

BeamerDelegate _routerDelegate = BeamerDelegate(
    routeListener: (RouteInformation routeInfo, _) {
      print(_routerDelegate.currentBeamLocation.state.routeInformation.location);
      _routerDelegate.currentPages.forEach((element) {print(element);});
    } ,
      transitionDelegate: const NoAnimationTransitionDelegate(),
      locationBuilder: RoutesLocationBuilder(
          routes: {
        '/home': (context, state, data) => BeamPage(key: const ValueKey('home'), child: Container(color: Colors.yellow)),
        '/notifications': (context, state, data) =>
            BeamPage(key: const ValueKey('notifications'), child: Container(color: Colors.pink)),
      }));

The router listener prints:

>> /home
>> BeamPage("null", [<'not-found'>], null)

So the BeamPage does not match the location. This only happens when I arrive at /home coming from the Guard redirect.

Also noted that doing _routerDelegate.addListener gives different results than using the routeListener which is confusing - when should I use one thing or the other?

jpiabrantes avatar Jul 08 '22 14:07 jpiabrantes