auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

Persistent navigation bar across all pages

Open MadsVETiSearch opened this issue 3 years ago • 4 comments

Ive set up my routes like this:

@AdaptiveAutoRouter( replaceInRouteName: 'Page,Route', routes: <AutoRoute>[ AutoRoute(page: LoadingPage, initial: true), AutoRoute( page: LoginPage, children: [ RedirectRoute(path: '*', redirectTo: ''), ], ), AutoRoute( path: '/', page: RootPage, children: [ AutoRoute( path: 'nye_produkter', name: 'NewProductsRouter', page: NewProductsPage, ), AutoRoute( path: 'recepter', name: 'PrescriptionsRouter', page: PrescriptionPage, ), AutoRoute( path: 'hjem', name: 'HomeRouter', page: HomePage, initial: true, ), AutoRoute( path: 'lister', name: 'ListsRouter', page: ClinicMedicinListsPage, ), AutoRoute( path: 'menu', name: 'MenuRouter', page: MenuPage, ), ], ), AutoRoute( path: 'settings', name: 'SettingsRouter', page: SettingsPage, children: [ AutoRoute( name: "StandardSpeciesRouter", page: StandardSpeciesPage, ), AutoRoute( name: 'UpdatePasswordRouter', page: UpdatePasswordPage, ), AutoRoute( name: 'UpdateProfilePictureRouter', page: UpdateProfilePicturePage, ), AutoRoute( name: 'UpdateSignatureRouter', page: UpdateSignaturePage, ), AutoRoute( name: 'UpdateUserInformationRouter', page: UpdateUserInformationPage, ), ], ) ], )

And the navigationbar works just fine, but when i navigate to Settings, the nav bar disappears, and that is because settings isnt nested within the root page, but when i do that and navigate to settings, i get the following error message Looks like you're trying to navigate to a nested route without adding their parent to stack first

is there any way to persist the navigation bar no matter which route i navigate to?

MadsVETiSearch avatar Aug 04 '22 09:08 MadsVETiSearch

@MadsVETiSearch You just need to push whatever parent route SettingsRoute is a child of. navigateTo(ParentRoute(children: [SettingsRoute()]);

Milad-Akarie avatar Aug 04 '22 11:08 Milad-Akarie

@Milad-Akarie First of all, thanks for the quick reply! I have another questiong, is it possible to keep navigation bar persistent and only push the screens to the body of the autotabscaffold?

MadsVETiSearch avatar Aug 05 '22 07:08 MadsVETiSearch

Sure, but each tab will have it's own stack

Milad-Akarie avatar Aug 05 '22 08:08 Milad-Akarie

I am having a similar issue, could not figure out how to give more children to my HomeRoute apart from the ones it has in the BottomNavBar.

This is a simplified version of my setup:

AutoRoute(
        path: '/home',
        page: HomeView,
        name: 'HomeRoute',
        initial: false,
        children: [
          AutoRoute(
            path: ':content',
            name: 'ContentRoute',
            page: ContentView,
          ),
          AutoRoute(
            path: 'new',
            name: 'NewPostRoute',
            page: NewPostView,
          ),
          AutoRoute(
            path: 'explore',
            name: 'ExploreRoute',
            page: ExploreView,
          ),
])

There are BottomNavBar items on the HomeView. I can navigate to my ExploreView, and I want to go to my ContentView in the ExploreView, the BottomNavBar persisting. The following doesn't work:

context.router.navigate(HomeRoute(
                children: [ContentRoute(content: content)],
              ));

But if I do the following when I am in the NewPostView, I go to ExploreView:

context.router.navigate(HomeRoute(
                children: [ExploreRoute()],
              ));

How can I go to the ContentView from my ExploreView, my BottomNavBar still persisting? Should I add my ContentRoute as a child to my ExploreRoute instead?

akbulutdora avatar Aug 23 '22 23:08 akbulutdora

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

github-actions[bot] avatar Dec 03 '22 08:12 github-actions[bot]