Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add deprecate messages for url.replaceTo and url.pushTo
  • Loading branch information
arunoda committed Dec 19, 2016
commit 949243f682083179abb0b3bf0b2a865fbcc9dd10
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -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.

Expand Down
7 changes: 4 additions & 3 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down