From e8d8d1b622b4e063cb70e0f758d563b065afe2cf Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Sat, 25 Feb 2017 13:08:51 -0300 Subject: [PATCH 1/3] Using developit/unfetch as the Fetch API polyfill --- lib/router/router.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/router/router.js b/lib/router/router.js index e3141a359770..a830726aee49 100644 --- a/lib/router/router.js +++ b/lib/router/router.js @@ -10,7 +10,7 @@ import { _notifyBuildIdMismatch } from './' // Add "fetch" polyfill for older browsers if (typeof window !== 'undefined') { - require('whatwg-fetch') + require('unfetch/polyfill') } export default class Router extends EventEmitter { diff --git a/package.json b/package.json index 04479de454d8..7536468c3a13 100644 --- a/package.json +++ b/package.json @@ -79,12 +79,12 @@ "source-map-support": "0.4.11", "strip-ansi": "3.0.1", "styled-jsx": "0.5.7", + "unfetch": "2.0.0", "url": "0.11.0", "uuid": "3.0.1", "webpack": "2.2.1", "webpack-dev-middleware": "1.10.1", "webpack-hot-middleware": "2.17.1", - "whatwg-fetch": "2.0.2", "write-file-webpack-plugin": "3.4.2" }, "devDependencies": { From de809841a869874b9a63bed40edc961dbc2c15f0 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Tue, 14 Mar 2017 13:05:41 -0500 Subject: [PATCH 2/3] Added the replace prop into the Link component --- lib/link.js | 6 +++++- readme.md | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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

From 0b5030e5c9c8ca8ccb2487ad90130d82b13090dc Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Tue, 14 Mar 2017 16:49:28 -0500 Subject: [PATCH 3/3] Added integration test for replace prop on Link component --- test/integration/basic/pages/nav/index.js | 1 + .../basic/test/client-navigation.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) 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