In StackOverflow, you can access question through two different URL
- /questions/:questionId/:slug
- /questions/:questionId
I am trying to build the Same.
GoRoute(
path: "${LeaderboardItemPage.route}/:creationId",
name: LeaderboardItemPage.route,
redirect: (
context,
state,
) {
final creationId = state.pathParameters['creationId'];
return "${LeaderboardItemPage.route}/$creationId/overview";
},
routes: [
/// same as a
GoRoute(
path: ":slug",
// pag
// name: LeaderboardItemPage.route,
builder: (BuildContext context, GoRouterState state) {
final creationId = state.pathParameters['creationId'];
final slug = state.pathParameters['slug'];
print("Slug: $slug");
if (creationId == null) {
return ErrorWidget();
}
return LeaderboardItemPage(
creationId: creationId,
);
},
),
],
),
This barely works, but has lots of issue. First of all , I am forcing a dummy slug
called overview
. What if I actually want it to be null and show a popup to the user asking to create a permalink ?
Secondly,
context.pushNamed(LeaderboardItemPage.route, pathParameters: {
'creationId': leaderboardItem.creationId,
'slug' : "some-slug"
});
return;
I get unknown param "slug" for /creations/:creationId
. I want to use the same routeName for both and still use the pathParameters
, not direct url