Commit fbd4f032 authored by Vinicius Camargo's avatar Vinicius Camargo Committed by Tim Neutkens

Update the custom-server-express with an req.params example (#3258)

parent e67d17ef
...@@ -5,5 +5,6 @@ export default () => ( ...@@ -5,5 +5,6 @@ export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li> <li><Link href='/b' as='/a'><a>a</a></Link></li>
<li><Link href='/a' as='/b'><a>b</a></Link></li> <li><Link href='/a' as='/b'><a>b</a></Link></li>
<li><Link href='/posts/2'><a>post #2</a></Link></li>
</ul> </ul>
) )
import React, { Component } from 'react'
export default class extends Component {
static getInitialProps ({ query: { id } }) {
return { postId: id }
}
render () {
return <div>
<h1>My blog post #{this.props.postId}</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
}
}
...@@ -18,6 +18,10 @@ app.prepare() ...@@ -18,6 +18,10 @@ app.prepare()
return app.render(req, res, '/a', req.query) return app.render(req, res, '/a', req.query)
}) })
server.get('/posts/:id', (req, res) => {
return app.render(req, res, '/posts', { id: req.params.id })
})
server.get('*', (req, res) => { server.get('*', (req, res) => {
return handle(req, res) return handle(req, res)
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment