Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] complex example with auto_route #1630

Closed
davidnwaneri opened this issue Jun 29, 2023 · 5 comments
Closed

[Question] complex example with auto_route #1630

davidnwaneri opened this issue Jun 29, 2023 · 5 comments

Comments

@davidnwaneri
Copy link
Contributor

Before v6 we had EmptyRoutePage

AutoRoute(page: EmptyRoutePage,name: 'ProfileRouter')

But after v6 its been removed. The alternative as mentioned in the docs is

@RoutePage(name: 'ProfileRouter')      
class ProfileRouterPage extends AutoRouter {}    

This is my route

...
AutoRoute(
          path: '/dashboard',
          guards: [AuthGuard(_context)],
          page: DashBoardRoute.page,
          children: [
            AutoRoute(
              path: 'home',
              page: HomeRoute.page,
            ),
            AutoRoute(
              page: ListRoute.page,
            ),
            AutoRoute(
              path: 'profile',
              page: ProfileRouter.page,
              children: [
                AutoRoute(
                  initial: true,
                  path: '',
                  page: ProfileRoute.page,
                ),
              ],
            ),
          ],
        ),

There are only two items in the bottom nav bar, HomeRoute and ListRoute . ProfileRoute is another screen entirely.
But when i try to push ProfileRoute from HomeRoute, my home route just rebuilds.
I use context.pushRoute(const ProfileRouter()); to push the HomeRoute. Please What am i doing wrong.

@davidnwaneri
Copy link
Contributor Author

AutoRoute(                    
      path: '/dashboard',                    
      page: DashboardRoute.page,                    
      children: [                    
        AutoRoute(path: '', page: UsersRoute.page),
        AutoRoute(
              path: 'profile',
              page: ProfileRouter.page,
              children: [
                AutoRoute(
                  initial: true,
                  path: '',
                  page: SettingsRoute.page,
                ),
              ],
            ),                                      
      ],                    
    ),

How do you deal with this, where SettingsRoute is a child of ProfileRoute, but it is not nested and can only be accessed from profile on the UI

@Milad-Akarie
Copy link
Owner

Hey @davidnwaneri I think the problem here is the location of your ProfileRouter in the hierarchy,
your setup should look like this

[
AutoRoute(
          path: '/dashboard',
          guards: [AuthGuard(_context)],
          page: DashBoardRoute.page,
          children: [
            AutoRoute(
              path: 'home',
              page: HomeRoute.page,
            ),
            AutoRoute(
              page: ListRoute.page,
            ),
     
          ],
        ),
      /// this should be in the root scope or any scope other than the tabsRouter scope
       AutoRoute(
              path: '/profile',
              page: ProfileRouter.page,
              children: [
                AutoRoute(
                  initial: true,
                  path: '',
                  page: ProfileRoute.page,
                ),
              ],
            ),
]

@davidnwaneri
Copy link
Contributor Author

@Milad-Akarie Thank you for taking out time to respond. This worked.

I had the wrong idea about declaring my routes. I've always thought dey should be declared the way they are accessed on the UI

@davidnwaneri
Copy link
Contributor Author

For more context - no pun intended - say I also had:

AutoRoute(
              path: '/profile',
              page: ProfileRouter.page,
              children: [
                AutoRoute(
                  initial: true,
                  path: '',
                  page: ProfileRoute.page,
                ),
                ...
               AutoRoute(
                  path: 'settings',
                  page: SettingsRoute.page,
                ),
              ],
            ),

Settings route could have children route. Will this be valid or SettingsRoute should be in the root scope?

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants