Improve parameter-values
See original GitHub issueSince Angular prerendering in general and angular-prerenderer specifially finally works for me, I now tried to care about the details. With no luck so far. It is great that angular-prerenderer offers the param parameter-values
, but its usage is either not well documented or it doesn’t work for my scenario.
Consider these route definitions
const routes: Routes = [
{
path: "/bar",
component: HomeComponent
},
{
path: "/route-i-want-to-prerender/:id/:title",
component: WhatEver
},
{
path: "/route-i-do-not-want-to-prerender/:id/:title",
component: AnotherOne,
}
]
First problem: Params have the same name across routes, but there is just one route for which I want to pass params (or I want to pass different params per route).
Second problem: There are multiple params per route. If I pass the params like
'{":id":["1","2","3"],":title":["foo1","foo2","foo3"]
I expect the routes below to be prerendered
- /route-i-want-to-prerender/1/foo1
- /route-i-want-to-prerender/2/foo2
- /route-i-want-to-prerender/3/foo3
However, instead of 3 routes, angular-prerenderer produced 9. I don’t get exactly what happens here, but it is wrong for my use case.
Finally, I’d prefer to be able to pass a JSON file (or a path pointing to a JSON file, to be more precise) instead of a string. That way, you get rid of escaping problems and you won’t run into any length restriction issues on the command line.
In my opinion, the expected structure of that JSON file should be something like this
{
"/route-i-want-to-prerender/:id/:title": [
{ ":id": "1", ":title": "foo1" },
{ ":id": "2", ":title": "foo2" },
{ ":id": "3", ":title": "foo3" }
],
"/another-route-i-want-to-prerender/:id/:title": [
{ ":id": "4", ":title": "bar4" },
{ ":id": "5", ":title": "bar5" },
{ ":id": "6", ":title": "bar6" }
],
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
Hi @cschwaderer,
thanks for filing this issue? Unfortunately the
--parameter-values
argument is not really usable for your use case. It currently renders each route with all possible permutations. And as you discovered the parameter values can’t be scoped to a specific route.I like the schema that you proposed. Building up on this I would propose the following.
This means a property of the JSON object can be either a parameter (
":id"
) or a route ("/x/y/z"
). If it starts with colon it’s considered to be a parameter and if it starts with a slash it’s considered to be a path.The values must be either a string or an array of strings.
Does that sound reasonable to you?
I’m glad it helps you.
Both of your examples should work. You could even get rid of a couple of more characters:
It’s only necessary to specify the portion of the route which is different from the others. I also allowed another schema to avoid the additional array in case there is only one set of parameter values per route. In that case you could use something like this…
Please let me know if that doesn’t work. In that case I introduced a bug.
Adding a JSON schema validation is an excellent idea. I’ll put it on the todo list.
I thought it makes the README simpler when I only use one parameter but I can see why that wasn’t a good idea. Thanks for your feedback.