In my main method I have
onGenerateRoute: (route) {
print(route);
return Router.generateRoute(route);
}
If I enter URL with https://myurl.com/#/foo/bar
I can see printing is called multiple times.
/
/foo
/foo/bar
I have an issue because I want to enter bar
path, but it gets entered foo
instead.
Any ideas how should I proceed?
It gets worse. Set the initalRoute to /home/1/2/3/4/5
and the onGenerateRoute will be called 7 times.
You can make it less terrible with:
MaterialApp app;
app = MaterialApp(
onGenerateInitialRoutes: (initialRoute)=>[app.onGenerateRoute(RouteSettings(name:initialRoute))],
initialRoute: initial,
onGenerateRoute: app.onGenerateRoute);
This avoid you're Route's initState being called multiple times and one onGenerateRoute per '/' in the path. However, is still calls onGenerateRoute twice if you supply a path in the browser bar.
I've submitted a bug report: https://github.com/flutter/flutter/issues/71786
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With