SchabanBo / qlevar_router

Manage you project Routes. Create nested routes. Simply navigation without context to your pages. Change only one sub widget in your page when navigating to new route.
MIT License
87 stars 22 forks source link

Global middlewares only apply to routes with other middlewares. #130

Closed k-ane closed 1 year ago

k-ane commented 1 year ago

I set my global middlewares like so:

QR.settings.globalMiddlewares.add(AuthMiddleware());

When navigating around the app, the middleware never triggers.

However if I add to each route something like this: middleware: [QMiddlewareBuilder()],

After doing that, my original global middleware starts working as expected.

k-ane commented 1 year ago

Doing some investigation seems this issue is related to line 403 of qrouter_controller.dart, since it only adds the MiddlewareController if the router has middleware.

I changed the line to this and it worked for me locally: if (route.hasMiddleware || (QR.settings.globalMiddlewares.isNotEmpty && !route.isNotFound)) {