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

Path '/' not working with QRoute.withChild #111

Closed gabriel-gheorghe closed 1 year ago

gabriel-gheorghe commented 1 year ago

Consider the next scenario:

final routes = [
  QRoute.withChild(
    path: '/',
    name: home,
    initRoute: '/about',
    builderChild: (router) => HomeScreen(router: router),
    children: [
      QRoute(
        path: '/about',
        name: about,
        builder: () => const AboutScreen(),
      ),
      QRoute(
        path: '/contact',
        name: contact,
        builder: () => const ContactScreen(),
      ),
    ],
  ),
];

It loads the AboutScreen inside the HomeScreen, but the path is missing from url. Also, when you try to switch to the ContactsScreen it navigates to the error page, the path still missing from the url.

If I change the path from '/' to '/home' or something else, it works properly, but I do not want to have 'home' inside the path.

carlosfiori commented 1 year ago

Hi @doublegarts,

Try this workaround, it works for me: Add initPath on MaterialApp.router to '/about' and update QRoute.withChild path to '/about' and change first route to /

Something like this:

final routes = [
  QRoute.withChild(
    path: '/about',
    name: home,
    builderChild: (router) => HomeScreen(router: router),
    children: [
      QRoute(
        path: '/',
        name: about,
        builder: () => const AboutScreen(),
      ),
      QRoute(
        path: '/contact',
        name: contact,
        builder: () => const ContactScreen(),
      ),
    ],
  ),
];
MaterialApp.router(
      routeInformationParser: const QRouteInformationParser(),
      routerDelegate: QRouterDelegate(
        AppRoutes().routes,
        initPath: '/about',
      ),
    );
SchabanBo commented 1 year ago

Yes, that was a problem since a long time now. But I have not had the time for it. And the workaround for it was as @carlosfiori mentioned. I fixed this in develop branch and will be out in the next release. The test for this is here