Try this:
Remove your initialRoute and routes from MaterialApp (if you use Material).
Use only onGenerateRoute e.g.:
onGenerateRoute: (settings) {
print(settings);
if (settings.name!.contains('?brd=BrandName') == false) {
return MaterialPageRoute(
builder: (context) {
return const HomePage();
},
settings: RouteSettings(
name: '?brd=BrandName', arguments: settings.arguments),
);
}
if (settings.name!.contains(DetailsPage.routeName)) {
final List<String> uri = settings.name!.split('/');
if (uri.length == 3) {
return MaterialPageRoute(
builder: (context) {
return DetailsPage(pageId: uri[2]);
},
settings: settings,
);
}
}
return MaterialPageRoute(
builder: (context) {
return const HomePage();
},
settings: settings,
);
},
In my example I have two pages:
Home - /#?brd=BrandName
Details - /#?brd=BrandName/details/2
Example with button:
ElevatedButton(
onPressed: () {
navigatorKey.currentState!
.pushNamed("?brd=BrandName/details/2");
},
child: const Text('Go to Page 1'),
)
P.S. When you change something in routers it is much better to reboot your application completely.