auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

Routing from FloatingButton to nested route

Open slashforward-nl opened this issue 2 years ago • 1 comments

First off all, thanks for this routing library, all works great. Now im trying to build nested routes and i think im doing something wrong or there is unexpected behaviour from the library.

I have the following routes:

@MaterialAutoRouter(
replaceInRouteName: 'Page,Route',            
  routes: <AutoRoute>[            
    AutoRoute(
      path: "", 
      page: HomePage, 
      name: "HomePageRoute",
      guards: [AuthGuard],
      children: [    
        AutoRoute(path: "", name: "DashboardPageRoute", page: DashboardPage),
        AutoRoute(path: "profile", name: "ProfilePageRoute", page: ProfilePage),
        AutoRoute(
          path: "products", 
          name: "ProductsRouter", 
          page: EmptyRouterPage,
          children: [
            AutoRoute(path: "", page: ProductOverviewPage),
            AutoRoute(path: "add", page: AddProductPage),
            RedirectRoute(path: '*', redirectTo: ''),
          ]
        ),
      ],
    ),
    AutoRoute(
      page: LoginPage, 
      name: 'LoginPageRoute',
      path: '/login'
    ),
  ],
)  

The homepage is a simple AutoTabsScaffold.

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(context) {
    return AutoTabsScaffold(
      routes: const [
        DashboardPageRoute(),
        ProfilePageRoute(),
      ],
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      floatingActionButton: FloatingActionButton(
        elevation: 0,
        onPressed: () {
          AutoRouter.of(context).push(
            const HomePageRoute(children: [
              ProductsRouter(children: [
                AddProductRoute()
              ])
            ]));
        },
        child: const Icon(Icons.add), 
      ),
      bottomNavigationBuilder: (_, tabsRouter) {
        return BottomNavigationBar(
          currentIndex: tabsRouter.activeIndex,
          onTap: tabsRouter.setActiveIndex,
          items: const [
            BottomNavigationBarItem(
              icon: Icon(Icons.book),
              label: 'Books',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.book),
              label: 'Profile',
            ),
          ],
        );
      },
    );
  }
}

The problem occurs when i try to navigate to a child of homepage / products / add. Im in the homepage page, press the add button but when i try to navigate to the add product page i just get the homepage again. I keep pushing the homepage on the stack. The child page doesnt show.

Hope you can help me!

Thanks in advance

Wouter

slashforward-nl avatar Jun 02 '22 06:06 slashforward-nl

@slashforward-nl try navigate instead of push

Milad-Akarie avatar Jun 28 '22 11:06 Milad-Akarie

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 Nov 03 '22 08:11 github-actions[bot]