How To Trick React Router Into Thinking `/` Is The Mount Directory?
Let's say I have a simple react app: import React from 'react'; import ReactDOM from 'react-dom'; import {BrowserRouter as Router, Route} from 'react-router-dom' import * as servic
Solution 1:
Follow the below steps :
- Set the basename
<Routerbasename={'/directory-name'}><Routepath='/'component={Home} />
{/* … */}
</Router>
- Set the app homepage(in package.json file)
"homepage": "https://myapp.com/directory-name",
- Update the Routes
Router basename={'/subdirectory'}>
<Routepath={`${process.env.PUBLIC_URL}/`} component={Home} /><Routepath={`${process.env.PUBLIC_URL}/news`} component={News} /><Routepath={`${process.env.PUBLIC_URL}/about`} component={About} />
</Router>
- Update the Links
<Link to={
${process.env.PUBLIC_URL}/page-path}>…</Link>
For detailed information , have a look at this link https://medium.com/@svinkle/how-to-deploy-a-react-app-to-a-subdirectory-f694d46427c1
Post a Comment for "How To Trick React Router Into Thinking `/` Is The Mount Directory?"