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

Lines changed: 5 additions & 3 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy