Skip to content

Commit

Permalink
Remove extra StaticRouter createHref leading slash (#4484)
Browse files Browse the repository at this point in the history
  • Loading branch information
pshrmn authored and timdorr committed Feb 7, 2017
1 parent f4f0fa3 commit a7e8888
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-router/modules/StaticRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class StaticRouter extends React.Component {
}

createHref = (path) =>
addLeadingSlash(this.props.basename) + createURL(path)
addLeadingSlash(this.props.basename + createURL(path))

handlePush = (location) => {
const { basename, context } = this.props
Expand Down
23 changes: 23 additions & 0 deletions packages/react-router/modules/__tests__/StaticRouter-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import expect from 'expect'
import React, { PropTypes } from 'react'
import ReactDOMServer from 'react-dom/server'
import ReactDOM from 'react-dom'
import StaticRouter from '../StaticRouter'
import Redirect from '../Redirect'
import Route from '../Route'
Expand Down Expand Up @@ -139,4 +140,26 @@ describe('A <StaticRouter>', () => {
expect(context.url).toBe('/the-base/somewhere-else')
})
})

describe('no basename', () => {
it('createHref does not append extra leading slash', () => {
const context = {}
const node = document.createElement('div')
const pathname = '/test-path-please-ignore'

const Link = ({ to, children }) => (
<Route children={({ createHref }) => (
<a href={createHref(to)}>{children}</a>
)} />
)

ReactDOM.render((
<StaticRouter context={context}>
<Link to={pathname} />
</StaticRouter>
), node)
const a = node.getElementsByTagName('a')[0]
expect(a.getAttribute('href')).toEqual(pathname)
})
})
})

0 comments on commit a7e8888

Please sign in to comment.