diff --git a/lib/link.js b/lib/link.js index 79dc8b61d5c1..87c4c32f00c1 100644 --- a/lib/link.js +++ b/lib/link.js @@ -56,8 +56,12 @@ export default class Link extends Component { scroll = as.indexOf('#') < 0 } + // replace state instead of push if prop is present + const { replace } = this.props + const changeMethod = replace ? 'replace' : 'push' + // straight up redirect - Router.push(href, as) + Router[changeMethod](href, as) .then((success) => { if (!success) return if (scroll) window.scrollTo(0, 0) diff --git a/readme.md b/readme.md index 4127feaedadf..21bfed1d3111 100644 --- a/readme.md +++ b/readme.md @@ -292,6 +292,16 @@ export default () => ( That will generate the URL string `/about?name=Zeit`, you can use every property as defined in the [Node.js URL module documentation](https://nodejs.org/api/url.html#url_url_strings_and_url_objects). +The default behaviour for the `` component is to `push` a new url into the stack. You can use the `replace` prop to prevent adding a new entry. + +```jsx +// pages/index.js +import Link from 'next/link' +export default () => ( +
Click here to read more
+) +``` + #### Imperatively

diff --git a/test/integration/basic/pages/nav/index.js b/test/integration/basic/pages/nav/index.js index 23cf4d23a8ed..fad7a15959ed 100644 --- a/test/integration/basic/pages/nav/index.js +++ b/test/integration/basic/pages/nav/index.js @@ -33,6 +33,7 @@ export default class extends Component { > QueryString + Replace state