From d92ab55d22ad55b3e00ef91800b2ec046bcb66f1 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Tue, 14 Mar 2017 18:06:34 -0500 Subject: [PATCH] Add/link replace (#1419) * Using developit/unfetch as the Fetch API polyfill * Added the replace prop into the Link component * Added integration test for replace prop on Link component --- lib/link.js | 6 +++- readme.md | 10 ++++++ test/integration/basic/pages/nav/index.js | 1 + .../basic/test/client-navigation.js | 34 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/link.js b/lib/link.js index 79dc8b61d5..87c4c32f00 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 4127feaeda..21bfed1d31 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 23cf4d23a8..fad7a15959 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