Вы можете перенаправить на определенную страницу для каждого запроса: (см. Команды на server.js)
server.js
const express = require('express')
const next = require('next')
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare().then(() => {
const server = express()
server.get('/blog', (req, res) => {
// @HERE: we redirect request from /blog to /blogs for general page
// so the detail can still be redirected to /blog
return app.render(req, res, '/blogs')
})
server.get('/blog/:id', (req, res) => {
return app.render(req, res, '/blog', { id: req.params.id })
})
server.get('*', (req, res) => {
return handle(req, res)
})
server.listen(port, err => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
})
blog.js
import React, { Component } from 'react'
export default class extends Component {
static getInitialProps ({ query: { id } }) {
return { blogId: id }
}
render () {
return (
<div>
<h1>blog {this.props.blogId}</h1>
</div>
)
}
}
blogs.js
import React, { Component } from 'react'
export default class extends Component {
render () {
return (
<div>
<a href="/blog/python">
Learn Python – Interactive <br/> Python
</a>
<a href="/blog/javascript">
Learn Javascript – Interactive <br/> Javascript
</a>
</div>
)
}
}