Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples: static export using dynamic routes instead express #9237

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/with-static-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ yarn dev

## The idea behind the example

This example show how to export to static HTML files your Next.js application fetching data from an API to generate a dynamic list of pages. This use a custom Express server in development to configure custom routing and then generate a map of pages to export for production.
This example show how to export to static HTML files your Next.js application fetching data from an API to generate a dynamic list of pages.

When trying to run `npm start` it will build and export your pages into the `out` folder and serve them on `localhost:5000`.
12 changes: 4 additions & 8 deletions examples/with-static-export/components/post.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import Link from 'next/link'

export default props => (
export default ({ title, body, id }) => (
<article>
<h2>{props.title}</h2>
<p>{props.body}</p>
{/* render the URL as /post/:id */}
<Link
href={{ pathname: '/post', query: { id: props.id } }}
as={`/post/${props.id}`}
>
<h2>{title}</h2>
<p>{body}</p>
<Link href='/post/[id]' as={`/post/${id}`}>
<a>Read more...</a>
</Link>
</article>
Expand Down
2 changes: 1 addition & 1 deletion examples/with-static-export/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
(pages, post) =>
Object.assign({}, pages, {
[`/post/${post.id}`]: {
page: '/post',
page: '/post/[id]',
query: { id: post.id }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
query: { id: post.id }

We should be able to remove this since we parse/provide it for dynamic routes automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, good point, I'll check it

}
}),
Expand Down
12 changes: 5 additions & 7 deletions examples/with-static-export/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"name": "with-static-export",
"main": "server.js",
"dependencies": {
"express": "^4.15.3",
"isomorphic-unfetch": "^2.0.0",
"isomorphic-unfetch": "^3.0.0",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"serve": "9.4.0"
"react": "^16.11.0",
"react-dom": "^16.11.0",
"serve": "11.2.0"
},
"scripts": {
"dev": "node .",
"dev": "next",
"build": "next build",
"preexport": "npm run build",
"export": "next export",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export default class extends Component {
}

render () {
const { title, body } = this.props

return (
<main>
<Head>
<title>{this.props.title}</title>
<title>{title}</title>
</Head>

<h1>{this.props.title}</h1>
<h1>{title}</h1>

<p>{this.props.body}</p>
<p>{body}</p>

<Link href='/'>
<a>Go back to home</a>
Expand Down
27 changes: 0 additions & 27 deletions examples/with-static-export/server.js

This file was deleted.