slovnicki / beamer

A routing package built on top of Router and Navigator's pages API, supporting arbitrary nested navigation, guards and more.
MIT License
582 stars 128 forks source link

Relative beaming ignore new routeState #623

Closed Panz99 closed 1 year ago

Panz99 commented 1 year ago

Describe the bug Using relative beaming to navigate, if some new routestate are provided they're ignored. So che beaminglocation routestate can't be updated.

Beamer version: 1.5.3

To Reproduce Steps to reproduce the behavior: Having a BeamLocation with this path : '/main/child'

  1. use beamToNamed to '/main' with routeState: {anydata: 'hello'}
  2. navigate using beamToNamed with relative beaming like: beamToNamed('child') with new routeState: {anydata: 'world'}
  3. the state of the current beamLocation is still {anydata: 'hello'}

Expected behavior The state now should be {anydata: 'world'}

Desktop (please complete the following information): -any

Smartphone (please complete the following information): -any

Additional context This problem happens only if we use a relative beaming. If we do beamToNamed('/main/child') with new routeState, the state is correctly updated. The problem is on the function maybeAppend of utils.dart, there the routeinformations are merged to handle the relative beaming, but the state is ignored.

static RouteInformation maybeAppend( RouteInformation current, RouteInformation incoming, ) { final incomingLocation = incoming.location; if (incomingLocation == null) { return current.copyWith(); } if (!incomingLocation.startsWith('/')) { return current.copyWith( location: current.location?.endsWith('/') ?? false ? '${current.location}$incomingLocation' : '${current.location}/$incomingLocation', ); } return incoming; }

slovnicki commented 1 year ago

Thanks for the PR #624! :blue_heart: