For new/edit routes I mostly want the view-model and view to be the same, so I would like to use url fragments in my route definition:
{
route: [":rId/edit", "new"], name: "edit",
moduleId: PLATFORM.moduleName("edit"), title: "Foo"
},
{ route: ":rId", name: "view", ... }
but I find there’s no way of choosing which url fragment gets used when routing from either a router.navigateToRoute()
or route-href
. e.g. I would want to do either to navigate:
-
this.router.navigateToRoute("edit", { rId: 123 });
or this.router.navigateToRoute("edit");
this works, in that both will route to the correct page, but the former creates the url:
-
/new?rId=123
instead of /123/edit
To get around it, I specify two route definitions that use the same module:
{
route: ":rId/edit", name: "edit",
moduleId: PLATFORM.moduleName("edit"), title: "Edit Foo"
},
{
route: "new", name: "new",
moduleId: PLATFORM.moduleName("edit"), title: "New Foo"
}
and now I can choose to navigate to “new” or “edit”.
Would it be possible to choose the url fragment (or allow the recognizer (I think it’s called) to choose the correct fragment based on how utilized the parameters are)?
My workaround works, but a bit less repetition would be ideal.
thanks!