kriasoft / universal-router

A simple middleware-style router for isomorphic JavaScript web apps
https://www.kriasoft.com/universal-router/
MIT License
1.7k stars 104 forks source link

Question: Routing based on backend logic #162

Closed mrmedicine closed 5 years ago

mrmedicine commented 5 years ago

Question

What would be a good / the best approach to make the following workflow possible?

  1. Universal-router, receives url '/some/page'
  2. Tries to fetch pageinfo based on '/some/page' from some backend.
  3. Either: finds the page and loads a generic react component, passes along data received from the backend to the component. Or: the page was not found in which case the "not found" component is returned.

Is it possible to write this logic in the resolveRoute(context, params); ?

mrmedicine commented 5 years ago

I plan to add this logic to https://github.com/kriasoft/react-starter-kit for server aswell as client routing, and can place the relevant code parts here, feel free to ask questions, thanks!

frenzzy commented 5 years ago

hi @mrmedicine, here is an example how you can implement it: https://github.com/kriasoft/react-starter-kit/pull/1237

mrmedicine commented 5 years ago

Thanks the answer was right in front of me all along.