Skip to content

Commit

Permalink
Shallow routing changes (#1363)
Browse files Browse the repository at this point in the history
* Fix a typo in a test suite.

* Add old props.url API with warn for all tags.
  • Loading branch information
arunoda authored and rauchg committed Mar 6, 2017
1 parent bbd1a97 commit 08d9847
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component, PropTypes } from 'react'
import { AppContainer } from 'react-hot-loader'
import shallowEquals from './shallow-equals'
import { warn } from './utils'

const ErrorDebug = process.env.NODE_ENV === 'production'
? null : require('./error-debug').default
Expand Down Expand Up @@ -65,6 +66,32 @@ class Container extends Component {
function createUrl (router) {
return {
query: router.query,
pathname: router.pathname
pathname: router.pathname,
back: () => {
warn(`Warning: 'url.back()' is deprecated. Use "window.history.back()"`)
router.back()
},
push: (url, as) => {
warn(`Warning: 'url.push()' is deprecated. Use "next/router" APIs.`)
return router.push(url, as)
},
pushTo: (href, as) => {
warn(`Warning: 'url.pushTo()' is deprecated. Use "next/router" APIs.`)
const pushRoute = as ? href : null
const pushUrl = as || href

return router.push(pushRoute, pushUrl)
},
replace: (url, as) => {
warn(`Warning: 'url.replace()' is deprecated. Use "next/router" APIs.`)
return router.replace(url, as)
},
replaceTo: (href, as) => {
warn(`Warning: 'url.replaceTo()' is deprecated. Use "next/router" APIs.`)
const replaceRoute = as ? href : null
const replaceUrl = as || href

return router.replace(replaceRoute, replaceUrl)
}
}
}
4 changes: 2 additions & 2 deletions test/integration/basic/test/client-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default (context, render) => {
})

describe('with shallow routing', () => {
it('should not update the url without running getInitialProps', async () => {
it('should update the url without running getInitialProps', async () => {
const browser = await webdriver(context.appPort, '/nav/shallow-routing')
const counter = await browser
.elementByCss('#increase').click()
Expand All @@ -196,7 +196,7 @@ export default (context, render) => {
await browser.close()
})

it('should handle back button and should not run getInitialProps', async () => {
it('should handle the back button and should not run getInitialProps', async () => {
const browser = await webdriver(context.appPort, '/nav/shallow-routing')
let counter = await browser
.elementByCss('#increase').click()
Expand Down

0 comments on commit 08d9847

Please sign in to comment.