How can I add custom routes to a user's app programmatically (plugin-like UX) #11609
Unanswered
paarthmadan
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
I'm the developer of a 3rd party app called Tempo which is responsible for running a user's app (
vite
withreact-router
). We have our ownnpm
package that is installed in the user's app.Goal
Our app requires the creation of some new routes in the user's app.
Ideally, after installing our package, we should be able to automatically/programatically add routes to the user's app. For example sake,
localhost:5173/tempo-route-a
andlocalhost:5173/tempo/route-b
More details
Right now, a user adds an initialization hook into their own app when they want to use Tempo:
This decorates their app with helpful artifacts.
Question
Is there anyway to get access to the list of routes and add more in at runtime? I've looked through the documentation and none of the hooks seem to mutate the state of the routing tree.
I'd also be open to something like:
I've played around with creating the HOC shown above, but to no avail. Most of the errors I've encountered have been related to using
Routes
oruseRoutes
outside the context of a<Router>
. I believe this has to do with referencing<Routes>
in the package directly.Discussion
TL;DR Is there any blessed/recommended path to being able to implement something like this. Ultimately, I want an easy way to add custom routes to a user's app after they run some sort of initializer.
Beta Was this translation helpful? Give feedback.
All reactions