Commit 905d6717 authored by Guillermo Rauch's avatar Guillermo Rauch Committed by GitHub

Update README.md

parent 141c045c
......@@ -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:
......
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