New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[go_router] Query Parameters are not preserved on pop
#116872
Comments
Triage reportI can reproduce this issue with Here is how the URLs look on web:
Expected URL should be Code Sampleimport 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
final GoRouter router = GoRouter(
routes: [
ShellRoute(
builder: (context, state, child) {
return Scaffold(
body: child,
bottomNavigationBar: Text(state.location),
);
},
routes: [
GoRoute(
path: '/',
builder: (context, state) {
return Page(
pageNo: 1,
argument: 'default',
onTap: () => router.go('/page2?a=apple'),
);
},
routes: [
GoRoute(
path: 'page2',
builder: (context, state) {
return Page(
pageNo: 2,
argument: state.queryParams['a'].toString(),
onTap: () => router.go('/page2/page3?b=ball'),
);
},
routes: [
GoRoute(
path: 'page3',
builder: (context, state) {
return Page(
pageNo: 3,
argument: state.queryParams['b'].toString(),
);
},
),
],
),
],
),
],
),
],
);
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Go Router Query Demo',
theme: ThemeData.from(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
),
routerConfig: router,
);
}
}
class Page extends StatelessWidget {
const Page({
super.key,
required this.pageNo,
required this.argument,
this.onTap,
});
final int pageNo;
final String argument;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
final nextPage = pageNo + 1;
return Scaffold(
appBar: AppBar(title: Text('Page $pageNo')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Argument: ${argument.toUpperCase()}'),
const SizedBox(height: 16),
ElevatedButton(
onPressed: onTap,
child: Text('Go to Page $nextPage'),
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: ElevatedButton(
onPressed: pageNo > 1 ? router.pop : null,
child: const Text('Go back'),
),
),
],
),
),
);
}
} |
Thanks for filing an issue, this is something we should fix. |
We are facing the same problem when developing our applcation. So any progress on this problem? will it be fixed soon? Now I am using extra to pass parameters to avoid this situation. |
We cannot use this router if that does not work. |
is it fixed ?? still happening... |
Same problem here! |
I'm facing the same issue, it seems to be pretty old: csells/go_router#170. It's a very strange behavior, this should have more priority. |
Any solution? |
it's not the perfect solution, but i found the workaround using this one |
Any change? I have same problem when I'm using " Navigator.pop(context)" querryParams are preserved. |
The issue persists on Go Router 12.1.3. I have updated the code sample of @exaby73 : Code sampleimport 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
final GoRouter router = GoRouter(
routes: [
ShellRoute(
builder: (context, state, child) {
return Scaffold(
body: child,
bottomNavigationBar: Text(GoRouterState.of(context).matchedLocation)
);
},
routes: [
GoRoute(
path: '/',
builder: (context, state) {
return Page(
pageNo: 1,
argument: 'default',
onTap: () => router.go('/page2?a=apple'),
);
},
routes: [
GoRoute(
path: 'page2',
builder: (context, state) {
return Page(
pageNo: 2,
argument: GoRouterState.of(context).uri.queryParameters['a'].toString(),
onTap: () => router.go('/page2/page3?b=ball'),
);
},
routes: [
GoRoute(
path: 'page3',
builder: (context, state) {
return Page(
pageNo: 3,
argument: GoRouterState.of(context).uri.queryParameters['b'].toString(),
);
},
),
],
),
],
),
],
),
],
);
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Go Router Query Demo',
theme: ThemeData.from(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
),
routerConfig: router,
);
}
}
class Page extends StatelessWidget {
const Page({
super.key,
required this.pageNo,
required this.argument,
this.onTap,
});
final int pageNo;
final String argument;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
final nextPage = pageNo + 1;
return Scaffold(
appBar: AppBar(title: Text('Page $pageNo')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Argument: ${argument.toUpperCase()}'),
const SizedBox(height: 16),
ElevatedButton(
onPressed: onTap,
child: Text('Go to Page $nextPage'),
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: ElevatedButton(
onPressed: pageNo > 1 ? router.pop : null,
child: const Text('Go back'),
),
),
],
),
),
);
}
} flutter doctor -v
|
This solved my issue |
Seems like there are two specific behaviors here. There's the concept of When we move I think the behavior most expected by devs is an API like
It would also be nice to augment this with a |
Any updates on this? The issue still exists to this date. |
Steps to Reproduce
Run the code snippet
Page 2
and thenPage 3
Go back
onceTested with:
go_router: ^5.2.4Expected results:
Actual results:
flutter doctor -v
The text was updated successfully, but these errors were encountered: