diff --git a/packages/react-router-dom/modules/Link.js b/packages/react-router-dom/modules/Link.js index 187ae69835..55f0aad7e5 100644 --- a/packages/react-router-dom/modules/Link.js +++ b/packages/react-router-dom/modules/Link.js @@ -48,8 +48,13 @@ class Link extends React.Component { const { history } = this.context.router const { replace, to } = this.props + const alreadyThere = (window && to === window.location.pathname) || + (document && to === document.location.pathname) + if (replace) { history.replace(to) + } else if (alreadyThere) { + // don't push the url we're already at } else { history.push(to) } diff --git a/packages/react-router-dom/modules/__tests__/Link-test.js b/packages/react-router-dom/modules/__tests__/Link-test.js index ef47cd27b1..7d0e1c03b8 100644 --- a/packages/react-router-dom/modules/__tests__/Link-test.js +++ b/packages/react-router-dom/modules/__tests__/Link-test.js @@ -66,6 +66,10 @@ describe('When a is clicked', () => { describe('and the onClick handler calls event.preventDefault()', () => { it('does not change the location') }) + + describe('and the URL already matches "to"', () => { + it('does not push the location') + }) }) describe('A underneath a ', () => {