`renderArgs.elements` is empty when navigating to the same route
See original GitHub issueIssue Description
In my app I sometimes have links from a route to the same route, but with different pathname
.
Those are forum Thread
pages: one thread could link to another thread.
In some previous versions renderArgs.elements
seemed to be always present, so my workaround of doing:
renderArgs.elements[renderArgs.elements.length - 1] =
React.cloneElement(renderArgs.elements[renderArgs.elements.length - 1], {
key: renderArgs.location.pathname
})
seemed to work.
It doesn’t seem to work anymore, because when navigating from a thread to another thread renderArgs.elements
seems to be undefined
.
Could it be the case?
If yes, perhaps could you propose any potential workaround for this case?
My current workaround is creating a wrapper over Thread
page component that would set a key
on the wrapped Thread
page — seems to work.
export default function ThreadPageWrapper() {
const board = useSelector(({ chan }) => chan.board)
const thread = useSelector(({ chan }) => chan.thread)
return <ThreadPage key={`${board.id}/${thread.id}`}/>
}
ThreadPageWrapper.meta = ThreadPage.meta
ThreadPageWrapper.load = ThreadPage.load
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Matched leaf route at location "/" does not have an element
In V6, you can't use the component prop anymore. It was replaced in favor of element : <Route path="/" element={<Home />}></Route>.
Read more >[v6-alpha.3] Route with empty path does not render nested ...
The use case is to render a common layout component for all routes, then a route component for index path. <Route path="" element={< ......
Read more >found - npm
Extensible route-based routing for React applications. ... In components rendered by the router, use <Link> to render links that navigate ...
Read more >NavController | Android Developers
static final void ... Navigate to a route in the current NavGraph. ... This assumes that the current graph shares the same hierarchy...
Read more >Layouts and Rendering in Rails - Ruby on Rails Guides
This method takes exactly the same options as render , but it returns a ... You can also do that with render ,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
yeah, makes sense. i think something like the static container approach we have right now is the best possible without suspense, but it doesn’t fully work with redux.
suspense makes all of this much easier. some day…
Ah, okay – in that place,
elements
is not necessarily defined. Reference https://github.com/4Catalyzer/found/blob/2b439b6f509c932f3a100f1deffed667b6dd55a6/src/createRender.js#L13-L34 – we could be in the “pending” or “error” branch. I’d just wrap your logic above in anif
block.If you were using
createRender
more-or-less directly to generate therender
function to pass into one of the routers, then you could also just put the logic inrenderFetched
there, but it looks like you have enough custom logic that it’d probably be easier just to use theif (renderArgs.elements)
in here.