From 9896c46cdeb8eefefbb9274f009b51ff015caa7d Mon Sep 17 00:00:00 2001 From: Paul Sherman Date: Tue, 7 Feb 2017 09:19:15 -0600 Subject: [PATCH] Remove extra StaticRouter createHref leading slash --- packages/react-router/modules/StaticRouter.js | 2 +- .../modules/__tests__/StaticRouter-test.js | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/react-router/modules/StaticRouter.js b/packages/react-router/modules/StaticRouter.js index b6c4d47c0a..14172a66d6 100644 --- a/packages/react-router/modules/StaticRouter.js +++ b/packages/react-router/modules/StaticRouter.js @@ -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 diff --git a/packages/react-router/modules/__tests__/StaticRouter-test.js b/packages/react-router/modules/__tests__/StaticRouter-test.js index 435c30b9d6..4f21074337 100644 --- a/packages/react-router/modules/__tests__/StaticRouter-test.js +++ b/packages/react-router/modules/__tests__/StaticRouter-test.js @@ -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' @@ -139,4 +140,26 @@ describe('A ', () => { 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 }) => ( + ( + {children} + )} /> + ) + + ReactDOM.render(( + + + + ), node) + const a = node.getElementsByTagName('a')[0] + expect(a.getAttribute('href')).toEqual(pathname) + }) + }) })