Skip to content

Improvement - Enable redirection with Route Guard when pathName is obtained asynchronously #1040

@joyce-massau

Description

@joyce-massau

Project Name
flutter_modular

Route Guard prevents redirection when the pathName is obtained asynchronously, because redirectTo is only defined in the constructor method:

Image

Describe the solution you'd like
A suggestion would be, to maintain backward compatibility and avoid break changes, to keep redirectTo in the constructor method, but also create a setter that would allow changing the constructor value if it initializes as null

Additional context
Consider the hypothetical situation that, if the user is logged in and tries to force a route via the URL that they do not have access to, they should go to one screen, and if they are logged out, they should go to another. User data can be retrieved synchronously in the singleton, but when the user reloads the page, they lose this data and it needs to be retrieved again asynchronously from LocalStorage.

Because of this, it's not possible to set the route directly in the constructor method, currently forcing the developer to use a less-than-ideal solution: forcing redirection instead of using what the documentation specifies (RouteGuard's redirectTo)

Image

I would like to work on this adjustment?
Yes, I would like to

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestnewNew issue request attention

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions