We have a rapidly growing React application which renders on both the server- and client-sides. Some sections of the app are on separate subdomains. The same app uses the same assets across many subdomains, so we control it all through the one runtime. This mean react-router needs to be able to distinguish which host or subdomain it's on.
HostRoute
which subclassesRoute
and is aware of the host via a static methodHostRoute.setHost(url.parse(res.url).hostname)
- Static method called before Router.run() (on init of app) i.e.
HostRoute.setHost(url.parse(req.url).hostname)
and/orHostRoute.setHost(window.location.hostname)
- Makes sense, since host will never change during the lifetime of the application, a significantly lighter approach and "opt-in" for those who require it.
- Will require addition to
modules/Match
to ask the Route itself if it might be a match (if host matches or isundefined
, returntrue
) - Not including
HostRoute
does not affect application.
- Add host="" param to
Route
, which takes either string (matchingendsWith
style) or a RegExp. - Add
getCurrentHost()
to HistoryLocation, HashLocation and friends - Add host support to
Match
, either first-class (as an argument innew Match(pathname, params, query, routes)
or by adding a sneaky keyparams.___host___
- Affects many lines of code, probably outside of the core scope of the react-router project.
Thoughts?