From e45cc89ce3c02c91418e473971c2191a874d2c0e Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Tue, 20 Dec 2016 00:19:15 +0530 Subject: [PATCH] Add deprecate messages for url.replaceTo and url.pushTo (#433) --- README.md | 12 +++++++----- lib/app.js | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 585c8b7d..9d88b2d7 100644 --- a/README.md +++ b/README.md @@ -173,10 +173,12 @@ Each top-level component receives a `url` property with the following API: - `pathname` - `String` of the current path excluding the query string - `query` - `Object` with the parsed query string. Defaults to `{}` -- `push(url)` - performs a `pushState` call associated with the current component -- `replace(url)` - performs a `replaceState` call associated with the current component +- `push(url, as=url)` - performs a `pushState` call with the given url +- `replace(url, as=url)` - performs a `replaceState` call with the given url -#### Imperatively +The second `as` parameter for `push` and `replace` is an optional _decoration_ of the URL. Useful if you configured custom routes on the server. + +#### Imperatively You can also do client-side page transitions using the `next/router` @@ -193,8 +195,8 @@ Above `Router` object comes with the following API: - `route` - `String` of the current route - `pathname` - `String` of the current path excluding the query string - `query` - `Object` with the parsed query string. Defaults to `{}` -- `push(url, as=url)` - performs a `pushState` call associated with the current component -- `replace(url, as=url)` - performs a `replaceState` call associated with the current component +- `push(url, as=url)` - performs a `pushState` call with the given url +- `replace(url, as=url)` - performs a `replaceState` call with the given url The second `as` parameter for `push` and `replace` is an optional _decoration_ of the URL. Useful if you configured custom routes on the server. diff --git a/lib/app.js b/lib/app.js index e0fcd43b..fe419c8a 100644 --- a/lib/app.js +++ b/lib/app.js @@ -61,20 +61,21 @@ export default class App extends Component { function propsToState (props) { const { Component, router } = props - const { route } = router const url = { query: router.query, pathname: router.pathname, back: () => router.back(), - push: (url) => router.push(route, url), + push: (url, as) => router.push(url, as), pushTo: (href, as) => { + console.warn(`Warning: 'url.pushTo()' is deprecated. Please use 'url.push()' instead.`) const pushRoute = as ? href : null const pushUrl = as || href return router.push(pushRoute, pushUrl) }, - replace: (url) => router.replace(route, url), + replace: (url, as) => router.replace(url, as), replaceTo: (href, as) => { + console.warn(`Warning: 'url.replaceTo()' is deprecated. Please use 'url.replace()' instead.`) const replaceRoute = as ? href : null const replaceUrl = as || href