1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add deprecate messages for url.replaceTo and url.pushTo (#433)

This commit is contained in:
Arunoda Susiripala 2016-12-20 00:19:15 +05:30 committed by Guillermo Rauch
parent a87ef1a7af
commit e45cc89ce3
2 changed files with 11 additions and 8 deletions

View file

@ -173,8 +173,10 @@ Each top-level component receives a `url` property with the following API:
- `pathname` - `String` of the current path excluding the query string - `pathname` - `String` of the current path excluding the query string
- `query` - `Object` with the parsed query string. Defaults to `{}` - `query` - `Object` with the parsed query string. Defaults to `{}`
- `push(url)` - performs a `pushState` call associated with the current component - `push(url, as=url)` - performs a `pushState` call with the given url
- `replace(url)` - performs a `replaceState` call associated with the current component - `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.
#### Imperatively #### Imperatively
@ -193,8 +195,8 @@ Above `Router` object comes with the following API:
- `route` - `String` of the current route - `route` - `String` of the current route
- `pathname` - `String` of the current path excluding the query string - `pathname` - `String` of the current path excluding the query string
- `query` - `Object` with the parsed query string. Defaults to `{}` - `query` - `Object` with the parsed query string. Defaults to `{}`
- `push(url, as=url)` - performs a `pushState` 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 associated with the current component - `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. The second `as` parameter for `push` and `replace` is an optional _decoration_ of the URL. Useful if you configured custom routes on the server.

View file

@ -61,20 +61,21 @@ export default class App extends Component {
function propsToState (props) { function propsToState (props) {
const { Component, router } = props const { Component, router } = props
const { route } = router
const url = { const url = {
query: router.query, query: router.query,
pathname: router.pathname, pathname: router.pathname,
back: () => router.back(), back: () => router.back(),
push: (url) => router.push(route, url), push: (url, as) => router.push(url, as),
pushTo: (href, as) => { pushTo: (href, as) => {
console.warn(`Warning: 'url.pushTo()' is deprecated. Please use 'url.push()' instead.`)
const pushRoute = as ? href : null const pushRoute = as ? href : null
const pushUrl = as || href const pushUrl = as || href
return router.push(pushRoute, pushUrl) return router.push(pushRoute, pushUrl)
}, },
replace: (url) => router.replace(route, url), replace: (url, as) => router.replace(url, as),
replaceTo: (href, as) => { replaceTo: (href, as) => {
console.warn(`Warning: 'url.replaceTo()' is deprecated. Please use 'url.replace()' instead.`)
const replaceRoute = as ? href : null const replaceRoute = as ? href : null
const replaceUrl = as || href const replaceUrl = as || href