reactjs / server-components-demo

Demo app of React Server Components.
https://reactjs.org/server-components
MIT License
4.25k stars 633 forks source link

Suggestion: new router #32

Open nbouvrette opened 3 years ago

nbouvrette commented 3 years ago

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:

Happy to join more discussions on these topics in the future.

tchak commented 3 years ago

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.

tchak commented 3 years ago

Hmm, it looks like context/provider API is not available in server components.

gaearon commented 3 years ago

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.

philipp-sapronov commented 3 years ago

@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