I’m working on a movie app
My goal is to build this navigation system:
- A root menu with these branches: home, search
- Both home (
/
) and search (/search
) have a movie card to open movie details page - Opening the movie details page should keep the root menu
I’ve tried having a StatefulShellRoute
with the corresponding home and search branches, each having it’s own movie details route:
GoRouter(
routes: [
StatefullShellRoute.indexedStack( // Root menu route
branches: [
StatefullShellBranch( // Home branch
routes: [
GoRoute( // Home route
path: '/',
routes: [GoRoute(path: 'movies/:id, ...)], // Movie route
),
],
),
StatefullShellBranch( // Search branch
routes: [
GoRoute( // Home route
path: '/search',
routes: [GoRoute(path: 'movies/:id, ...)], // Movie route again
),
],
),
],
),
],
)
But this solution has 2 drawbacks:
- Opening movie details from search causes
'/search/movies/:id'
path, while I want it to be'/movies/:id'
no matter where user gets there from - Routes duplicating, which is gonna become a hell with the project growth (for example, a movie route will have many of it’s own subroutes like franchise, so these routes are gonna be duplicated too)
Trying to declare the movie route outside the branches causes movie details without root menu
Is there a way to solve all of these 3 problems together?