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

Shallow routing changes (#1363)

* Fix a typo in a test suite.

* Add old props.url API with warn for all tags.
This commit is contained in:
Arunoda Susiripala 2017-03-06 23:44:10 +05:30 committed by Guillermo Rauch
parent bbd1a97aa9
commit 08d9847ab7
2 changed files with 30 additions and 3 deletions

View file

@ -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
@ -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)
}
}
}

View file

@ -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()
@ -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()