mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Update README.md
This commit is contained in:
parent
141c045c68
commit
905d671719
37
README.md
37
README.md
|
@ -12,8 +12,8 @@ Next.js is a minimalistic framework for server-rendered React applications.
|
|||
|
||||
Install it:
|
||||
|
||||
```
|
||||
$ npm install next --save
|
||||
```bash
|
||||
npm install next --save
|
||||
```
|
||||
|
||||
and add a script to your package.json like this:
|
||||
|
@ -274,6 +274,39 @@ export default ({ url }) => (
|
|||
)
|
||||
```
|
||||
|
||||
### Custom server and routing
|
||||
|
||||
Typically you start your next server with `next start`. It's possible, however, to start a server 100% programmatically in order to customize routes, use route patterns, etc
|
||||
|
||||
This example makes `/a` resolve to `./pages/b`, and `/b` resolve to `./pages/a`:
|
||||
|
||||
```
|
||||
const { createServer } = require('http')
|
||||
const { parse } = require('url')
|
||||
const next = require('next')
|
||||
|
||||
const app = next({ dev: true })
|
||||
const handle = app.getRequestHandler()
|
||||
|
||||
app.prepare().then(() => {
|
||||
createServer((req, res) => {
|
||||
const { pathname, query } = parse(req.url, true)
|
||||
|
||||
if (pathname === '/a') {
|
||||
app.render(req, res, '/b', query)
|
||||
} else if (pathname === '/b') {
|
||||
app.render(req, res, '/a', query)
|
||||
} else {
|
||||
handle(req, res)
|
||||
}
|
||||
})
|
||||
.listen(3000, (err) => {
|
||||
if (err) throw err
|
||||
console.log('> Ready on http://localhost:3000')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
### Custom `<Document>`
|
||||
|
||||
Pages in `Next.js` skip the definition of the surrounding document's markup. For example, you never include `<html>`, `<body>`, etc. But we still make it possible to override that:
|
||||
|
|
Loading…
Reference in a new issue