lulupointu / vrouter

MIT License
202 stars 38 forks source link

Back button when dealing with path parameters #185

Closed danieldoddjr closed 1 year ago

danieldoddjr commented 2 years ago

I am using path parameters in my routes.

VWidget(
  path: '/tickets',
  widget: const TicketsScreen(),
  stackedRoutes: [
    VWidget(
      path: 'create-ticket',
      widget: CreateTicketScreen(),
    ),
    // back button goes back to tickets instead of the ticket
    VWidget(
      path: ':id/update-ticket-subject',
      widget: UpdateTicketSubjectScreen(),
    ),
    // back button goes back to tickets instead of the ticket
    VWidget(
      path: ':id/update-ticket-message',
      widget: UpdateTicketMessageScreen(),
    ),
    // back button goes back to tickets instead of the ticket
    VWidget(
      path: ':id/update-comment/:commentId',
      widget: UpdateCommentScreen(),
    ),
    VWidget(
      path: ':id',
      widget: const TicketScreen(),
    ),
  ],
),

This works great except when I hit the back button it goes back to the main tickets route when the desired effect is landing back on the ticket thats being edited.

Thanks for this awesome package!

lulupointu commented 1 year ago

The back button pops the top VWidget. In your case what you seem to want would be the following structure:

VWidget(
  path: '/tickets',
  widget: const TicketsScreen(),
  stackedRoutes: [
    VWidget(
      path: 'create-ticket',
      widget: CreateTicketScreen(),
    ),
    VWidget(
      path: ':id',
      widget: const TicketScreen(),
      stackedRoutes: [
        // back button goes back to tickets instead of the ticket
        VWidget(
          path: 'update-ticket-subject',
          widget: UpdateTicketSubjectScreen(),
        ),
        // back button goes back to tickets instead of the ticket
        VWidget(
          path: 'update-ticket-message',
          widget: UpdateTicketMessageScreen(),
        ),
        // back button goes back to tickets instead of the ticket
        VWidget(
          path: 'update-comment/:commentId',
          widget: UpdateCommentScreen(),
        ),
      ],
    ),
  ],
)

In which case popping from tickets/1/update-ticket-subject will go to tickets/1.

Feel free to reopen if you need more help.