server-components-demo
server-components-demo copied to clipboard
Suggestion: new router
This demo looks promising - I recall the mention of the need for a new router (from the video presenting the demo)? I don't know who is working on this but a few ideas:
- Would be nice to have a router that can be used both by the server and client
- Include localization from the beginning (I could not find a popular solution to localize URLs when using React)
- Probably related to the previous bullet, but the localized URLs should use the same strings file as other localized string - might be good to combine some sort of i18n provider that can be used both by the server and client
Happy to join more discussions on these topics in the future.
I tried to integrate react-router with this demo. I think it should mostly just work with v6-experimental branch (https://github.com/ReactTraining/react-router/releases/tag/v0.0.0-experimental-ffd8c7d0). But I am having issues with webpack build on the server when I start adding dependencies.
Hmm, it looks like context/provider API is not available in server components.
Yes, routing is a big research area and it would need at the very least some notion of Server Context. There’s a lot to work out there.
@nbouvrette
You can use react-router components without context as well (When the same logic is implemented). Client component has to be returned from Switch / Route server components in order to use server + client routing. For me it works with react-router-dom. The only parameter required by the server router to create the Match object is the URL, you can pass it to the application from the request.
Here's my example of using server components: https://github.com/philipp-sapronov/react-server-components-app