fix(@angular/ssr): support getPrerenderParams for wildcard routes#30072
fix(@angular/ssr): support getPrerenderParams for wildcard routes#30072alan-agius4 merged 1 commit intoangular:mainfrom
getPrerenderParams for wildcard routes#30072Conversation
dde7bb8 to
9585353
Compare
e583b67 to
ff6d1b4
Compare
ff6d1b4 to
bb94a89
Compare
dgp1130
left a comment
There was a problem hiding this comment.
What about a path like '/product/:first/**/:second'? Not sure if we allow segments after ** (reading this PR, seems like no?), but presumably we at least allow them before? Is this feature limited to either /:first xor /**?
I feel like we could support both with something like:
{
path: '/product/:first/**/:second',
renderMode: RenderMode.Prerender,
async getPrerenderParams() {
return [
{'first': 'foo', __spread__: ['category', '1'], 'second': 'bar'},
{'first': 'bar', __spread__: ['category', '2'], 'second': 'foo'},
];
}
}Not sure exactly the right way of identifying the spread array though. Maybe a Symbol imported from @angular/ssr?
Is there a better way of mixing ** and :foo syntax in the same path? Is :foo/** a rare enough pattern that we just don't care at this stage?
Edit |
bb94a89 to
02cf4f4
Compare
What about |
Yes, this is not handled at the moment, maybe the simplest would be to allow something like instead of changing the signature of the function {
path: '/product/:first/**',
renderMode: RenderMode.Prerender,
async getPrerenderParams() {
return [
{'first': 'foo', '**': 'category/1', 'second': 'bar'},
];
}
} |
02cf4f4 to
5cd43cf
Compare
|
Would it be worth getting some wider feedback from the team (Andrew or Jan in particular)? Maybe a quick one-pager would be enough to get some quick thoughts on the approach. I'm open to |
|
I like Afaict there's no pre-existing name for the value captured from the wildcard. |
|
@atscott, any thoughts? |
|
@AndrewKushnir might also have some quick thoughts here. |
I'm wondering what are the use-cases for this feature? What would be "hiding" behind the Potentially, we can apply the following rules:
However, I'm not sure if that would be too limiting for the use-cases that this feature is improving. |
One example is when catch-all routes need to be prerendered. For instance, see this issue: #30035. In such cases, parameterized routes can't be used effectively because the nesting depth is arbitrary. As for the rules you mentioned, those sound good to me, and I don't see them as restrictive. |
5cd43cf to
b701a6c
Compare
|
@dgp1130 PTAL |
b701a6c to
698d16e
Compare
| }); | ||
| const routeWithResolvedParams = currentRoutePath | ||
| .replace(URL_PARAMETER_REGEXP, handlePrerenderParamsReplacement(params, currentRoutePath)) | ||
| .replace(CATCH_ALL_REGEXP, handlePrerenderParamsReplacement(params, currentRoutePath)); |
There was a problem hiding this comment.
Question: What happens if the user does foo/**/bar? Do they at least get an error?
There was a problem hiding this comment.
You already get an error for that as it's not a valid angular router route.
| * { id: '1', '**': '/laptop/123' }, | ||
| * { id: '2', '**': '/laptop/456' } |
There was a problem hiding this comment.
Nit: Is the leading slash necessary? If not, I'd probably leave it off given that this is replacing a ** which is already preceded by a slash.
698d16e to
7293914
Compare
Handle `getPrerenderParams` return values when used with wildcard route paths, including support for combined routes like `/product/:id/**`.
Supports returning an array of path segments (e.g., `['category', '123']`) for `**` routes and dynamic segments combined with catch-all routes.
This enables more flexible prerendering configurations in server routes, including handling specific paths such as `/product/1/laptop/123`.
Example:
```ts
{
path: '/product/:id/**',
renderMode: RenderMode.Prerender,
async getPrerenderParams() {
return [
{ id: '1', '**': 'laptop/123' },
{ id: '2', '**': 'laptop/456' }
];
}
}
```
Closes angular#30035
7293914 to
cb3446e
Compare
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Handle
getPrerenderParamsreturn values when used with wildcard route paths, including support for combined routes like/product/:id/**.Supports returning an array of path segments (e.g.,
['category', '123']) for**routes and dynamic segments combined with catch-all routes.This enables more flexible prerendering configurations in server routes, including handling specific paths such as
/product/1/laptop/123.Example:
Closes #30035