reach / router

Home Page:https://reach.tech/router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Export BaseContext for deep integration

haffmaestro opened this issue · comments

I'm attempting to integrate Reach Router with a legacy React app, with a lot of routes and an already existing routing system. The app is too big to migrate all routes in one go, so I need to make using ReachRouter, opt in.

LocationProvider get's me half of the way there, every ReachRouter component/hook which receives a route, works.

However, for Link and useNavigate++, I need to use my own navigate. I've already tested that exporting BaseContext solves all of my problems.

diff --git a/src/index.js b/src/index.js
index a44bdb4..fb181aa 100644
--- a/src/index.js
+++ b/src/index.js
@@ -658,6 +658,7 @@ export {
   Match,
   Redirect,
   Router,
+  BaseContext,
   ServerLocation,
   createHistory,
   createMemorySource,

I'd be happy to make a PR to export it, but I was thinking you'd maybe want to have a component called BaseContextProvider or something like it.

Thanks for any responses 🙏

After reading the source more thoroughly I realized that using LocationProvider does exactly this. Thanks for making this great library!