React-router app deployed on dynamic subdirectory. Manual navigation using the <Navigate to={} />
doesn't work
#11190
Unanswered
hakunamatata97k
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
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there :)
I'm using React-Router-Dom and Vite on my project.
The app will be deployed onto a dynamic subdirectory that is not known pre-deployment.
Thus, using the solution found here: I set the base name of the router to match whatever the value of the
/generatedsubdirectory
.The in-app routing is triggered by the user via UI buttons in the app.
Per example:
example.com/generatedsubdirectory/view
→ Button click → URL changes toexample.com/generatedsubdirectory/secondview
and<MobileElement />
is displayed. The same applies from/secondview
→/view
.The Problem:
In App navigation as shown in the above example works, BUT When the user manually navigates to
/secondview
by tying the/secondview
in the browser URL field, the router doesn't return anything!Basically any route that involve:
<Navigate to={Constants.AppRoutes.ROUTE_XYZ} />
doesn't support manual navigation!.The code:
Here is the code:
.env
router.tsx:
Constants.ts:
App.ts
I have read the documentation of the React-Router but haven't found a solution yet.
Beta Was this translation helpful? Give feedback.
All reactions