Skip to content

Commit 08d9847

Browse files
arunodarauchg
authored andcommitted
Shallow routing changes (#1363)
* Fix a typo in a test suite. * Add old props.url API with warn for all tags.
1 parent bbd1a97 commit 08d9847

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/app.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component, PropTypes } from 'react'
22
import { AppContainer } from 'react-hot-loader'
33
import shallowEquals from './shallow-equals'
4+
import { warn } from './utils'
45

56
const ErrorDebug = process.env.NODE_ENV === 'production'
67
? null : require('./error-debug').default
@@ -65,6 +66,32 @@ class Container extends Component {
6566
function createUrl (router) {
6667
return {
6768
query: router.query,
68-
pathname: router.pathname
69+
pathname: router.pathname,
70+
back: () => {
71+
warn(`Warning: 'url.back()' is deprecated. Use "window.history.back()"`)
72+
router.back()
73+
},
74+
push: (url, as) => {
75+
warn(`Warning: 'url.push()' is deprecated. Use "next/router" APIs.`)
76+
return router.push(url, as)
77+
},
78+
pushTo: (href, as) => {
79+
warn(`Warning: 'url.pushTo()' is deprecated. Use "next/router" APIs.`)
80+
const pushRoute = as ? href : null
81+
const pushUrl = as || href
82+
83+
return router.push(pushRoute, pushUrl)
84+
},
85+
replace: (url, as) => {
86+
warn(`Warning: 'url.replace()' is deprecated. Use "next/router" APIs.`)
87+
return router.replace(url, as)
88+
},
89+
replaceTo: (href, as) => {
90+
warn(`Warning: 'url.replaceTo()' is deprecated. Use "next/router" APIs.`)
91+
const replaceRoute = as ? href : null
92+
const replaceUrl = as || href
93+
94+
return router.replace(replaceRoute, replaceUrl)
95+
}
6996
}
7097
}

test/integration/basic/test/client-navigation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default (context, render) => {
181181
})
182182

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

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

0 commit comments

Comments
 (0)