react-router
react-router copied to clipboard
Dynamic routing vs absolute path in root
Hi,
The root url of my app is something like "localhost/MyApp/". I'm trying to set up dynamic routing using plain routes, but I'm unable to set the path of my root route to /MyApp/. Is this a suported scenario?
Sample code:
var childRoutes = [{
<Route path="About" component="About" /> },
<Route path="Home" component="Home" /> }
}];
var routes = {
path: "/MyApp/",
component: Root,
getChildRoutes: (location, callback) => {
callback(null, childRoutes);
}
}
ReactDOM.render(<Router>{routes}</Router>), reactContainer);
In this example, getChildRoutes is never called, unless I change the root path from "/MyApp/" to "/". But in this case, I'm matching the root path of my server which is NOT what I want to achieve, because all my app components live inside /MyApp/. Is there a workaround for this scenario?
Cheers
Basename Support is probably what you are looking for! :)
thanks for the answer @edvinerikson