Skip to content

Commit 0487956

Browse files
remyrauchg
authored andcommitted
docs: don't blow away existing query string (vercel#1638)
* docs: don't blow away existing query string See comments in diff - I ran across this and it took me a while to work out why my client side code worked, but the server didn't. It was because I didn't realise that `.render`'s 3rd arg was the query object, so it was losing the _actual_ query string. * chore: remove trailing spaces ¯\_(ツ)_/¯ I think!
1 parent feb6281 commit 0487956

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

examples/parameterized-routing/server.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ const match = route('/blog/:id')
1212
app.prepare()
1313
.then(() => {
1414
createServer((req, res) => {
15-
const { pathname } = parse(req.url)
15+
const { pathname, query } = parse(req.url, true)
1616
const params = match(pathname)
1717
if (params === false) {
1818
handle(req, res)
1919
return
2020
}
21-
22-
app.render(req, res, '/blog', params)
21+
// assigning `query` into the params means that we still
22+
// get the query string passed to our application
23+
// i.e. /blog/foo?show-comments=true
24+
app.render(req, res, '/blog', Object.assign(params, query))
2325
})
2426
.listen(3000, (err) => {
2527
if (err) throw err

0 commit comments

Comments
 (0)