Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # examples/with-markdown/readme.md # lib/page-loader.js # package.json # server/build/plugins/pages-plugin.js
- Loading branch information
Showing
256 changed files
with
4,338 additions
and
632 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Build directory not writeable | ||
|
||
#### Why This Error Occurred | ||
|
||
The filesystem does not allow writing to the specified directory. A common cause for this error is starting a [custom server](https://github.com/zeit/next.js#custom-server-and-routing) in development mode on a production server, for example, [now.sh](https://zeit.co) which [doesn't allow you to write to the filesystem after your app is built](https://zeit.co/docs/deployment-types/node#file-system-specifications). | ||
|
||
#### Possible Ways to Fix It | ||
|
||
When using a custom server with a server file, for example called `server.js`, make sure you update the scripts key in `package.json` to: | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"dev": "node server.js", | ||
"build": "next build", | ||
"start": "NODE_ENV=production node server.js" | ||
} | ||
} | ||
``` | ||
|
||
and the custom server starts Next in production mode when `NODE_ENV` is `production` | ||
|
||
```js | ||
const dev = process.env.NODE_ENV !== 'production' | ||
const app = next({ dev }) | ||
``` | ||
|
||
### Useful Links | ||
|
||
- [Custom Server documentation + examples](https://github.com/zeit/next.js#custom-server-and-routing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/active-class-name) | ||
|
||
# activeClassName example | ||
|
||
## How to use | ||
|
||
### Using `create-next-app` | ||
|
||
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example: | ||
|
||
``` | ||
npm i -g create-next-app | ||
create-next-app --example active-class-name active-class-name-app | ||
``` | ||
|
||
### Download manually | ||
|
||
Download the example [or clone the repo](https://github.com/zeit/next.js): | ||
|
||
```bash | ||
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/active-class-name | ||
cd active-class-name | ||
``` | ||
|
||
Install it and run: | ||
|
||
```bash | ||
npm install | ||
npm run dev | ||
``` | ||
|
||
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) | ||
|
||
```bash | ||
now | ||
``` | ||
|
||
## The idea behind the example | ||
|
||
ReactRouter has a convenience property on the `Link` element to allow an author to set the _active_ className on a link. This example replicates that functionality using Next's own `Link`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { withRouter } from 'next/router' | ||
import Link from 'next/link' | ||
import React, { Children } from 'react' | ||
|
||
const ActiveLink = ({ router, children, ...props }) => { | ||
const child = Children.only(children) | ||
|
||
let className = child.props.className || '' | ||
if (router.pathname === props.href && props.activeClassName) { | ||
className = `${className} ${props.activeClassName}`.trim() | ||
} | ||
|
||
delete props.activeClassName | ||
|
||
return <Link {...props}>{React.cloneElement(child, { className })}</Link> | ||
} | ||
|
||
export default withRouter(ActiveLink) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Link from './Link' | ||
|
||
export default () => ( | ||
<nav> | ||
<style jsx>{` | ||
.active:after { | ||
content: ' (current page)'; | ||
} | ||
.nav-link { | ||
text-decoration: none; | ||
padding: 10px; | ||
display: block; | ||
} | ||
`}</style> | ||
|
||
<ul> | ||
<li> | ||
<Link activeClassName='active' href='/'> | ||
<a className='nav-link home-link'>Home</a> | ||
</Link> | ||
</li> | ||
<li> | ||
<Link activeClassName='active' href='/about'> | ||
<a className='nav-link'>About</a> | ||
</Link> | ||
</li> | ||
</ul> | ||
</nav> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "active-class-name", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"author": "Remy Sharp <remy@leftlogic.com>", | ||
"dependencies": { | ||
"next": "latest", | ||
"react": "^16.0.0", | ||
"react-dom": "^16.0.0" | ||
}, | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Nav from '../components/Nav' | ||
|
||
export default () => ( | ||
<div> | ||
<Nav /> | ||
<p>Hello, I'm About.js</p> | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Nav from '../components/Nav' | ||
|
||
export default () => ( | ||
<div> | ||
<Nav /> | ||
<p>Hello, I'm the home page</p> | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
const pathWrapper = (app, pathName, opts) => ({ raw, query }, hapiReply) => | ||
app.renderToHTML(raw.req, raw.res, pathName, query, opts) | ||
.then(hapiReply) | ||
const { parse } = require('url') | ||
|
||
const defaultHandlerWrapper = app => { | ||
const nextHandlerWrapper = app => { | ||
const handler = app.getRequestHandler() | ||
return ({ raw, url }, hapiReply) => | ||
handler(raw.req, raw.res, url) | ||
.then(() => { | ||
hapiReply.close(false) | ||
}) | ||
return async ({ raw, url }, h) => { | ||
await handler(raw.req, raw.res, url) | ||
return h.close | ||
} | ||
} | ||
module.exports = { pathWrapper, defaultHandlerWrapper } | ||
const defaultHandlerWrapper = app => async ({ raw: { req, res }, url }) => { | ||
const { pathname, query } = parse(url, true) | ||
return app.renderToHTML(req, res, pathname, query) | ||
} | ||
|
||
const pathWrapper = (app, pathName, opts) => async ({ raw, query, params }) => { | ||
return app.renderToHTML(raw.req, raw.res, pathName, { ...query, ...params }, opts) | ||
} | ||
|
||
module.exports = { pathWrapper, defaultHandlerWrapper, nextHandlerWrapper } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.