SchabanBo / qlevar_router

Manage you project Routes. Create nested routes. Simply navigation without context to your pages. Change only one sub widget in your page when navigating to new route.
MIT License
87 stars 22 forks source link

Nested child doesn’t update on back after page reload #112

Closed carlosfiori closed 1 year ago

carlosfiori commented 1 year ago

When navigate back after a page reload the child page isn't reloaded.

Steps to reproduce:

  1. Click "To second"
  2. Reload page trough browser
  3. Click browser back button

Page should be home instead of second

Example code (click to expand): ```dart import 'package:flutter/material.dart'; import 'package:qlevar_router/qlevar_router.dart'; class App extends StatelessWidget { const App({super.key}); @override Widget build(BuildContext context) { return MaterialApp.router( routeInformationParser: const QRouteInformationParser(), routerDelegate: QRouterDelegate( AppRoutes().routes, initPath: '/dash', ), ); } } class AppRoutes { static const String homePage = 'Home Page'; static const String secondPage = 'Second Page'; final routes = [ QRoute.withChild( path: '/dash', builderChild: (child) { final routeName = child.routeName; return Scaffold( appBar: AppBar( title: Text(routeName), ), body: child, ); }, children: [ const QRoute( name: homePage, path: '/', builder: HomePage.new, ), const QRoute( name: secondPage, path: '/second', builder: SecondPage.new, ), ], ), ]; } class HomePage extends StatelessWidget { const HomePage({super.key}); @override Widget build(BuildContext context) { return Column( children: [ const Center(child: Text('Home')), ElevatedButton( onPressed: () { QR.toName(AppRoutes.secondPage); }, child: const Text('To second'), ), ], ); } } class SecondPage extends StatelessWidget { const SecondPage({super.key}); @override Widget build(BuildContext context) { return Column( children: [ const Center(child: Text('Second Page')), ElevatedButton( onPressed: () { QR.toName(AppRoutes.homePage); }, child: const Text('To Home'), ), ], ); } } void main() { runApp(const App()); } ```
SchabanBo commented 1 year ago

Hi @carlosfiori , if you want to always add the initroute in the stack, even after a restart, you need to set QRouterDelegate.alwaysAddInitPath to true. But there was an error even then that I have fixed. See the test.