Comments (7)
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.
- The current functionality keeps the same if you specify the JSON as this it will render 9 routes:
{
":id": ["1","2","3"],
":title": ["foo1","foo2","foo3"]
}
- Additionally it should be possible to group parameters. This will only render 3 routes:
[
{":id":["1"], ":title":["foo1"]},
{":id":["2"], ":title":["foo2"]},
{":id":["3"], ":title":["foo3"]}
]
- And finally as you proposed it should be possible to scope parameters by routes:
{
"/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" }
],
}
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?
from angular-prerender.
@chrisguttandin Thanks for reacting so fast! Yes, that sounds very reasonable to me in general.
Just one question for your second case:
[
{":id":["1"], ":title":["foo1"]},
{":id":["2"], ":title":["foo2"]},
{":id":["3"], ":title":["foo3"]}
]
Why do the values need to be an array here? Wouldn't flat values like
[
{":id":"1", ":title":"foo1"},
{":id":"2", ":title":"foo2"},
{":id":"3", ":title":"foo3"}
]
be better and clearer in this case?
from angular-prerender.
Oh, sorry for not pointing that out. I think both should work. I'm trying to get the update done by the end of the week.
from angular-prerender.
Hi @cschwaderer, v5.3 should support your use case now. Please let me know if you run into any issues.
from angular-prerender.
I also updated the readme. Could you please have a look and tell me if you think it sufficiently explains how --parameter-values
work.
from angular-prerender.
Thank you so much for implementing this to fast! Really helps me!
Now, first of all, just one question.
Instead of (as stated above)
{
"/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" }
],
}
the expected input is now
[
{ "/route-i-want-to-prerender/:id/:title": { ":id": "1", ":title": "foo1" }},
{ "/route-i-want-to-prerender/:id/:title": { ":id": "2", ":title": "foo2" }},
{ "/route-i-want-to-prerender/:id/:title": { ":id": "3", ":title": "foo3" }},
{ "/another-route-i-want-to-prerender/:id/:title": { ":id": "4", ":title": "bar4" }},
{ "/another-route-i-want-to-prerender/:id/:title": { ":id": "5", ":title": "bar5" }},
{ "/another-route-i-want-to-prerender/:id/:title": { ":id": "6", ":title": "bar6" }}
]
Is that on purpose for internal reasons? Because for the user, it's a little bit more verbose this way.
Additionally, since you asked me if the readme is clear enough, I'd say your example for this case is a somehow incomplete.
First of all, it's confusing because the routes used as an example do not contain params. Also, using at least two values per route would make clearer how it should look like.
My suggestion would be:
[{"/shirts/:id":{":id":"shirt-a"},{"/shirts/:id":{":id":"shirt-b"},"/shoes/:id":{":id":"shoe-a"}},"/shoes/:id":{":id":"shoe-b"}}]
As a last point: When passing wrong formatted values for --parameter-values
, angular-prerenderer doesn't tell exactly what is wrong right now. You might want to think about including some kind of JSON schema check (I personally use https://github.com/tdegrunt/jsonschema for such cases) in order to provide more detailed errors.
from angular-prerender.
I'm glad it helps you.
Both of your examples should work. You could even get rid of a couple of more characters:
{
"/route-i-want-to-prerender": [
{ ":id": "1", ":title": "foo1" },
{ ":id": "2", ":title": "foo2" },
{ ":id": "3", ":title": "foo3" }
],
"/another-route-i-want-to-prerender": [
{ ":id": "4", ":title": "bar4" },
{ ":id": "5", ":title": "bar5" },
{ ":id": "6", ":title": "bar6" }
]
}
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...
{
"/route-i-want-to-prerender": { ":id": "1", ":title": "foo1" },
"/another-route-i-want-to-prerender": { ":id": "4", ":title": "bar4" }
}
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.
from angular-prerender.
Related Issues (20)
- Argument `--parameter-values` gives JSON parse error HOT 14
- An in-range update of husky is breaking the build 🚨 HOT 2
- An in-range update of guess-parser is breaking the build 🚨 HOT 1
- An in-range update of @angular-devkit/core is breaking the build 🚨 HOT 1
- "Multiple root routing modules" error when one lazy loading module is loaded from another HOT 6
- An in-range update of eslint-config-holy-grail is breaking the build 🚨 HOT 1
- Atob is not defined HOT 4
- Add changelog HOT 1
- Support request: possible to deploy as cloud function? HOT 5
- Feature request: add support for `--exclude-routes *` HOT 9
- Please install ts-evaluator instead HOT 5
- duplicate app state in prerendered page HOT 8
- Feature Request: option for prerendering routes from a txt file --include-routes-file HOT 1
- Not picking up the routes array in angular.json HOT 9
- An in-range update of tsconfig-holy-grail is breaking the build 🚨 HOT 1
- Basic project example seems to be missing a step HOT 4
- How to use this plugin with https://prerender.io/ HOT 2
- An in-range update of core-js is breaking the build 🚨 HOT 1
- angular-prerender creates huge HTML file with CSS and source map HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-prerender.