phenomic icon indicating copy to clipboard operation
phenomic copied to clipboard

Static build can't handle named path parameter

Open thangngoc89 opened this issue 8 years ago • 4 comments

I have a named parameter in a route like this one

<Route
      path="/keywords/:keyword"
      component={createContainer(
        KeywordDetailsRoute.jsComponent,
        KeywordDetailsRoute.queries
      )}
    />

It works flawlessly on dev mode build static build can't resolve it. This is what the folder structure looks like:

image

If this is something that can't be analyzed during static build then we should warns user in dev mode.

thangngoc89 avatar Dec 26 '17 18:12 thangngoc89

hmm. After I edited it to use * it still can't generate keywords page

thangngoc89 avatar Dec 26 '17 19:12 thangngoc89

Actually, this is a limitation / bug ? (cc @MoOx) After debugging this, here's what I do to have prerender routes for relations:

Assuming we have a package like this:

{
  keywords: ["a", "b", "c"]
}

Case 1: using named parameter

On the route definition, we must use keywords as route parameter like this:

<Route
  path="/keywords/:keywords"
  component={KeywordDetailRoute}
/>

Case 2: Using a star (*)

I'm 99% sure that this is a bug. On this line

https://github.com/phenomic/phenomic/blob/33258f441b44302841ebe055319741d3ed985581/packages/core/src/prerender/resolve.js#L137

the condition check key === mainKey only pass when rendering a direct mapping (in this case a package), it's not working for relations(tags, keywords, ...) which is use as the key in comparison.

I tried to remove the condition check and it works for my use cases, not sure if there is any consequences.

thangngoc89 avatar Dec 26 '17 20:12 thangngoc89

Indeed, we do not do any magic to resolve a word to its plural version like it was in 0.x (tags => tag, category => categories - we were trying "y => ies" and "+s").

Indeed for meta we need the name (I think). Not sure what is the best to improve the situation. The * can make sense for ids, but for a named parameter... How do we know the name?

MoOx avatar Dec 27 '17 21:12 MoOx

I have an idea for this. Workinf on a PoC

thangngoc89 avatar Dec 28 '17 05:12 thangngoc89