Skip to content

Commit 07725d7

Browse files
chentsulintimdorr
authored andcommitted
Pass basename to StaticRouter for createHref
1 parent bb3e264 commit 07725d7

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

modules/BrowserRouter.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const BrowserRouter = ({ basename, keyLength, ...rest }) => (
1111
<StaticRouter
1212
action={action}
1313
location={location}
14+
basename={basename}
1415
onPush={history.push}
1516
onReplace={history.replace}
1617
blockTransitions={history.block}

modules/HashRouter.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const HashRouter = ({ basename, hashType, ...rest }) => (
1111
<StaticRouter
1212
action={action}
1313
location={location}
14+
basename={basename}
1415
onPush={history.push}
1516
onReplace={history.replace}
1617
onGo={history.go}

modules/StaticRouter.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class StaticRouter extends React.Component {
2020
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.func ]),
2121
createHref: PropTypes.func.isRequired,
2222
location: PropTypes.oneOfType([ PropTypes.object, PropTypes.string ]).isRequired,
23+
basename: PropTypes.string,
2324
onPush: PropTypes.func.isRequired,
2425
onReplace: PropTypes.func.isRequired,
2526
stringifyQuery: PropTypes.func.isRequired,
@@ -45,7 +46,10 @@ class StaticRouter extends React.Component {
4546

4647
getChildContext() {
4748
const createHref = (to) => {
48-
const path = createRouterPath(to, this.props.stringifyQuery)
49+
const path = createRouterPath(
50+
this.props.basename ? this.props.basename + to : to,
51+
this.props.stringifyQuery
52+
)
4953
return this.props.createHref(path)
5054
}
5155

0 commit comments

Comments
 (0)