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

Programmatic routes for static builds #32

Closed
johno opened this issue Dec 29, 2017 · 1 comment
Closed

Programmatic routes for static builds #32

johno opened this issue Dec 29, 2017 · 1 comment
Assignees

Comments

@johno
Copy link
Member

johno commented Dec 29, 2017

Currently we only support specifying routes under the x0 key in the package.json. There are scenarios where we want to build all possible routes as part of the build process.

For example, consider the following:

import React from 'react'
import fetch from 'isomorphic-fetch'

import {
  StaticRouter,
  BrowserRouter,
  Route
} from 'react-router-dom'

const Router = typeof document === 'undefined' ? StaticRouter : BrowserRouter

const Blog = props =>
  <Router>
    <div>
      <Route exact path='/' render={() => <h1>Hello, world!</h1>} />
      <Route path='/posts/:post' render={() => <h1>Post</h1>} />
    </div>
  </Router>

Blog.getInitialProps = async () => {
  const posts = await fetch('https://example.com/foo/bar')
  return { posts }
}

export default Blog

Ideally we'd be able to run a prebuild script which fetches any routes and writes to a json file that x0 can optionally read during a static build. This would handle scenarios where we have dynamic routing data we want static builds for. So, upon build, any current posts would have their respective pages generated.

@johno johno self-assigned this Dec 29, 2017
@jxnblk
Copy link
Member

jxnblk commented Jun 19, 2018

Closing this in favor of #70 since the API has changed since this was opened

@jxnblk jxnblk closed this as completed Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants