Open StefanGilligan opened 1 month ago
Use navigate and navigateNamed instead of push
Same issues unfortunately.
context.navigateTo(BookRoute(bookId: "test"));
FlutterError (Failed to navigate to BookRoute)
AutoRouter.of(context).navigateNamed('/books/test')
Navigates to the book page but loses all history.
AutoRouter.of(context).navigateNamed('/books/test', includePrefixMatches: true)
Navigates to the book page but pressing 'back' goes to the 'Books' page rather than the 'Home' screen
I'm trying to achieve the flow: On Home screen -> press button to go to individual book which is in a separate tab -> press back to go to the Home screen
@StefanGilligan were able to do it?
@StefanGilligan were able to do it?
Unfortunately not
For this case your route structure might look like this:
@AutoRouterConfig()
class AppRouter extends $AppRouter {
@override
List<AutoRoute> get routes => [
AutoRoute(
path: '/',
page: RootRoute.page,
initial: true,
children: [
AutoRoute(
path: 'home',
page: HomeScreenProxyRoute.page,
children: [
AutoRoute(
path: '',
page: HomeRoute.page,
),
],
),
AutoRoute(
path: 'books',
page: BooksScreenProxyRoute.page,
children: [
AutoRoute(path: '', page: BooksRoute.page),
],
),
],
AutoRoute(path: 'books/:id', page: BookRoute.page),
),
];
}
With your implementation when BookRoute
is pushed router stack would be RootRoute -> BooksScreen -> BookRoute
. With this implementation router stack is RootRoute -> BookRoute
whether it is pushed from HomeScreen
or from BooksScreen
I have two tabs: Home and Books. Each can have sub-pages (e.g. Books tab has individual books as pages).
I would very much like to be able to push an individual book page onto the stack from the Home screen. I would then expect the back button to take me back to the Home screen.
Here's my AppRouter:
Here's my HomeScreen:
context.pushRoute(BookRoute(bookId: "test"));
won't work (Failed to navigate to BookRoute)AutoRouter.of(context).pushNamed('/books/test')
navigates to the book screen, but there's no back button.AutoRouter.of(context).pushNamed('/books/test', includePrefixMatches: true)
navigates to the book screen but the back button goes to the 'Books' tab rather than back to the 'Home' screen.