Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0332488

Browse files
timneutkensrauchg
authored andcommitted
Add asPath on the server (vercel#3149)
* Add asPath on the server* Make sure we don’t include `?` when there is no query
1 parent40bb56e commit0332488

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

‎server/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async function doRender (req, res, pathname, query, {
7070
constapp=createElement(App,{
7171
Component:enhancer(Component),
7272
props,
73-
router:newRouter(pathname,query)
73+
router:newRouter(pathname,query,asPath)
7474
})
7575

7676
constrender=staticMarkup ?renderToStaticMarkup :renderToString

‎test/integration/basic/pages/nav/with-hoc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const Link = withRouter(({router, children, href}) => {
88

99
return(
1010
<div>
11-
<span>Current path:{router.pathname}</span>
11+
<spanid='pathname'>Current path:{router.pathname}</span>
12+
<spanid='asPath'>Current asPath:{router.asPath}</span>
1213
<ahref='#'onClick={handleClick}>{children}</a>
1314
</div>
1415
)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,11 @@ export default (context, render) => {
407407
it('should navigate as expected',async()=>{
408408
constbrowser=awaitwebdriver(context.appPort,'/nav/with-hoc')
409409

410-
constspanText=awaitbrowser.elementByCss('span').text()
411-
expect(spanText).toBe('Current path: /nav/with-hoc')
410+
constpathname=awaitbrowser.elementByCss('#pathname').text()
411+
expect(pathname).toBe('Current path: /nav/with-hoc')
412+
413+
constasPath=awaitbrowser.elementByCss('#asPath').text()
414+
expect(asPath).toBe('Current asPath: /nav/with-hoc')
412415

413416
consttext=awaitbrowser
414417
.elementByCss('.nav-with-hoc a').click()

‎test/integration/basic/test/rendering.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global describe, test, expect */
1+
/* global describe, test,it,expect */
22

33
importcheeriofrom'cheerio'
44

@@ -79,5 +79,19 @@ export default function ({ app }, suiteName, render) {
7979
expect($('h1').text()).toBe('404')
8080
expect($('h2').text()).toBe('This page could not be found.')
8181
})
82+
83+
describe('with the HOC based router',()=>{
84+
it('should navigate as expected',async()=>{
85+
const$=awaitget$('/nav/with-hoc')
86+
87+
expect($('#pathname').text()).toBe('Current path: /nav/with-hoc')
88+
})
89+
90+
it('should include asPath',async()=>{
91+
const$=awaitget$('/nav/with-hoc')
92+
93+
expect($('#asPath').text()).toBe('Current asPath: /nav/with-hoc')
94+
})
95+
})
8296
})
8397
}

‎test/lib/next-test-utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ export const nextBuild = build
1717
exportconstnextExport=_export
1818
exportconstpkg=_pkg
1919

20-
exportfunctionrenderViaAPI(app,pathname,query={}){
21-
consturl=`${pathname}?${qs.stringify(query)}`
20+
exportfunctionrenderViaAPI(app,pathname,query){
21+
consturl=`${pathname}${query ?`?${qs.stringify(query)}` :''}`
2222
returnapp.renderToHTML({ url},{},pathname,query)
2323
}
2424

25-
exportfunctionrenderViaHTTP(appPort,pathname,query={}){
26-
consturl=`http://localhost:${appPort}${pathname}?${qs.stringify(query)}`
25+
exportfunctionrenderViaHTTP(appPort,pathname,query){
26+
consturl=`http://localhost:${appPort}${pathname}${query ?`?${qs.stringify(query)}` :''}`
2727
returnfetch(url).then((res)=>res.text())
2828
}
2929

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp