File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -46,10 +46,8 @@ class StaticRouter extends React.Component {
46
46
47
47
getChildContext ( ) {
48
48
const createHref = ( to ) => {
49
- const path = createRouterPath (
50
- this . props . basename ? this . props . basename + to : to ,
51
- this . props . stringifyQuery
52
- )
49
+ let path = createRouterPath ( to , this . props . stringifyQuery )
50
+ if ( this . props . basename ) path = this . props . basename + path
53
51
return this . props . createHref ( path )
54
52
}
55
53
Original file line number Diff line number Diff line change 1
1
import expect from 'expect'
2
2
import React from 'react'
3
3
import StaticRouter from '../StaticRouter'
4
+ import { router as routerType } from '../PropTypes'
4
5
import { renderToString } from 'react-dom/server'
5
6
6
7
//console.error = () => {}
@@ -187,4 +188,32 @@ describe('StaticRouter', () => {
187
188
188
189
} )
189
190
} )
191
+
192
+ describe ( 'basename support' , ( ) => {
193
+ class Test extends React . Component {
194
+ static contextTypes = {
195
+ router : routerType
196
+ }
197
+
198
+ render ( ) {
199
+ return < div > { this . context . router . createHref ( '/bar' ) } </ div >
200
+ }
201
+ }
202
+
203
+ const BASENAME = "/foo"
204
+ const routerProps = {
205
+ location : '/' ,
206
+ action : 'POP' ,
207
+ onPush : ( ) => { } ,
208
+ onReplace : ( ) => { }
209
+ }
210
+
211
+ it ( 'uses the basename when creating hrefs' , ( ) => {
212
+ expect ( renderToString (
213
+ < StaticRouter { ...routerProps } basename = { BASENAME } >
214
+ < Test />
215
+ </ StaticRouter >
216
+ ) ) . toContain ( BASENAME )
217
+ } )
218
+ } )
190
219
} )
You can’t perform that action at this time.
0 commit comments