I'm using React-Router 1.0.0-rc3 together with Redux-Router 1.0.0-beta3.
When using React-Router, you can use useBasename
with createHistory
to set the base URL for an app, so that you can easily write an app that runs inside a subdirectory. Example:
Instead of this:
import { createHistory } from 'history';
let base = "/app_name/"
<Router history={browserHistory}>
<Route path={base} component={App}></Route>
</Router>
<Link path={base + "some_path"}>some_path</Link>
You can write in this way using useBasename
:
import { createHistory, useBasename } from 'history';
const browserHistory = useBasename(createHistory)({
basename: "/app_name"
});
<Router history={browserHistory}>
<Route path="/" component={App}></Route>
</Router>
<Link path="/some_path">some_path</Link>
However, in Redux-Router, you need to pass createHistory
instead of history
to a reducer:
const store = compose(
applyMiddleware(m1, m2, m3),
reduxReactRouter({
routes,
createHistory
}),
devTools()
)(createStore)(reducer);
How can we use useBasename
in this case?