GoRouter: Refresh on page looses Back Button

Viewed 25

I have a home screen and a detail page. When I navigate to the detail page, Flutter automatically adds a back button in the AppBar that when clicked, goes back to the previous page.

Now using GoRouter, the UrlPathStrategy.path allows that my detail page is at /detail and when refreshing the page, it opens the detail page directly. This is all good, however, the problem is, there is no back button after refreshing at /detail.

Is there a concept, such that GoRouter can infer the Navigation stack based on the route and thus when opening the /detail page, show a back button that leads to / (home page)?

My current routes look something like this:

routes: [
  GoRoute(
    name: "detail",
    path: "/detail",
    builder: (context, state) => DetailPage(),
  ),
  GoRoute(
    name: "home",
    path: "/",
    builder: (context, state) => HomePage(),
  ),
],
1 Answers

Probably just put detail route inside home route?

routes: [
  GoRoute(
    name: "home",
    path: "/",
    builder: (context, state) => HomePage(),
    routes: [
      GoRoute(
        name: "detail",
        path: "/detail",
        builder: (context, state) => DetailPage(),
      ),
    ],
  ),
],
Related