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

[1.0] Upgrade React Router to v4 #940

Merged
merged 18 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Stop using term 'routes'
  • Loading branch information
KyleAMathews committed May 11, 2017
commit 711a25d5e5149c2b09ab75f8a1221085502c7444
8 changes: 4 additions & 4 deletions packages/gatsby/lib/cache-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import ReactDOM from "react-dom"
import { BrowserRouter as Router, Route, withRouter } from "react-router-dom"
import { ScrollContext } from "react-router-scroll"
import createHistory from "history/createBrowserHistory"
import routes from "./routes.json"
import pages from "./pages.json"

import requires from "./async-requires"

console.log(routes)
console.log(pages)
console.log(requires)

// Load scripts
Expand All @@ -28,7 +28,7 @@ const loadScriptsForPath = (path, cb = () => {}) => {
return cb(scriptsCache[path])
}

const page = routes.find(r => r.path === path)
const page = pages.find(r => r.path === path)

if (!page) {
return cb()
Expand Down Expand Up @@ -100,7 +100,7 @@ loadScriptsForPath(`/404.html`, scripts => {
})

const renderPage = props => {
const page = routes.find(r => r.path === props.location.pathname)
const page = pages.find(r => r.path === props.location.pathname)
if (page) {
return $(scriptsCache[props.location.pathname].component, {
...props,
Expand Down
11 changes: 5 additions & 6 deletions packages/gatsby/lib/cache-dir/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { ScrollContext } from "react-router-scroll"
import createHistory from "history/createBrowserHistory"

import apiRunner from "./api-runner-browser"
// import rootRoute from "./child-routes"
import syncRequires from "./sync-requires"
import routes from "./routes.json"
console.log(routes)
import pages from "./pages.json"

console.log(pages)

const history = createHistory()
history.listen((location, action) => {
Expand All @@ -39,8 +39,7 @@ function shouldUpdateScroll(prevRouterProps, { location: { pathname } }) {

const $ = React.createElement

const filteredRoutes = routes.filter(r => r.path !== `/404.html`)
const noMatch = routes.find(r => r.path === `/404.html`)
const noMatch = pages.find(r => r.path === `/404.html`)

const addNotFoundRoute = () => {
if (noMatch) {
Expand Down Expand Up @@ -76,7 +75,7 @@ const Root = () =>
component: routeProps => {
window.___history = routeProps.history
const props = layoutProps ? layoutProps : routeProps
const page = routes.find(
const page = pages.find(
route => route.path === props.location.pathname
)
if (page) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/lib/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StaticRouter, Route, withRouter } from "react-router-dom"
import Html from "../src/html"
import { kebabCase, get, merge } from "lodash"
import apiRunner from "./api-runner-ssr"
import pages from "./routes.json"
import pages from "./pages.json"
import syncRequires from "./sync-requires"

const pathChunkName = path => {
Expand Down
10 changes: 5 additions & 5 deletions packages/gatsby/lib/query-runner/route-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {
pathChunkName,
} from "../utils/js-chunk-names"

// Write out routes file.
// Write out pages file.
// Loop through all paths and write them out to child-routes.js
const writeChildRoutes = () => {
const { program, config, pages } = store.getState()

// Write out routes.json
const routesData = pages.reduce(
// Write out pages.json
const pagesData = pages.reduce(
(mem, { path, componentChunkName, layout, jsonName }) => [
...mem,
{ componentChunkName, layout, jsonName, path },
Expand Down Expand Up @@ -50,8 +50,8 @@ const writeChildRoutes = () => {
components = _.uniqBy(components, c => c.componentChunkName)

fs.writeFile(
`${program.directory}/.cache/routes.json`,
JSON.stringify(routesData, null, 4)
`${program.directory}/.cache/pages.json`,
JSON.stringify(pagesData, null, 4)
)

// Create file with sync requires of layouts/components/json files.
Expand Down