lukepighetti / fluro

Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.
https://pub.dev/packages/fluro
MIT License
3.66k stars 416 forks source link

navigateTo not finding route #256

Open achilds97 opened 2 years ago

achilds97 commented 2 years ago

I am using fluro to handle the routing for our web app. I am able to get everything working using the standard Navigator.pushNamed, but when I try and use FluroRouter.appRouter.navigateTo so that I can pass in a custom class that is handling the session data.

When I use navigateTo flutter returns an error saying no route was found to handle 'dashboard'

Here is my code where I set up the routes:


  static Handler _homeHandler = Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
    return MyApp();
  });

  static Handler _dashboardHandler = Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
    final session = context!.settings!.arguments as Session;

    return DashboardScreen(session: session);
  });

  static Handler _siteHandler = Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    final session = context!.settings!.arguments as Session;

    return SiteScreen(siteName: params['id']![0], session: session);
  });

  static void setupRouter() {
    router.define(
      '/',
      handler: _homeHandler,
    );

    router.define(
      'dashboard',
      handler: _dashboardHandler,
    );

    print("defining sites/:id");
    router.define(
      'sites/:id',
      handler: _siteHandler
    );
  }

and then I am calling it in the onSelectChanged of a datatable like this:

      FluroRouter.appRouter.navigateTo(
        context,
        'dashboard',
        routeSettings: RouteSettings(
          arguments: session,
        ),
      );