Replies: 2 comments
-
Bringing over the discussion to github from discord. Thanks @rossipedia
Couldn't this line https://github.com/remix-run/react-router/blob/fbe796a4c5f257d710b2f779235e0cbcaef25396/packages/react-router/lib/components.tsx#L1128 be changed to instead of simply checking if the if (element.type !== Route) {
if (typeof element === "function") {
if (type in (element)().type !== Route) {
`[${typeof element.type === "string" ? element.type : element.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`
}
} else {
`[${typeof element.type === "string" ? element.type : element.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`
}
} That was just coded here, there's a few things missing since I'm not doing it in the editor... the idea is basically just to check if it's a function or something that returns Route elements and then just treat the result as the element itself. What do you think?
Can anyone please chime in? |
Beta Was this translation helpful? Give feedback.
-
I just want to note that:
|
Beta Was this translation helpful? Give feedback.
-
Hi, I'm trying to extend RR library mode for my use case, and while I can extend it by having a function that generates routes, I wanted to make it more idiomatic react by having components which would return components themselves, for example
That code would itself return a regular
Route
component.However I get the following error:
A very similar code that instead just calls a function
{makeNamedRoutes({name: "Term", path: "term", element: <div>a</div>})}
actually does work.It seems the reason is that the
Route
component doesn't evaluate the component in case it's not a route itself, and therefore it becomes not extensible.Is there a workaround for this?
Is it possible to request a change to make this functionality possible? I think this is a pretty straightforward case of extensibility which is surprisingly not allowed
Beta Was this translation helpful? Give feedback.
All reactions