Skip to content

Commit e77053a

Browse files
KyleAMathewsporfirioribeiro
authored andcommitted
Fix simple-auth's build (gatsbyjs#7175)
* Fix simple-auth's build * Fix getting pageResources for client routes
1 parent a667db8 commit e77053a

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

examples/simple-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "1.0.0",
55
"author": "Jason Lengstorf <jason@lengstorf.com>",
66
"dependencies": {
7-
"gatsby": "next",
7+
"gatsby": "^2.0.0-beta.91",
88
"gatsby-plugin-react-helmet": "next",
99
"prop-types": "^15.6.1",
1010
"react": "^16.4.0",

examples/simple-auth/src/components/PrivateRoute.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import React from "react"
22
import PropTypes from "prop-types"
3-
import { Router, navigate } from "@reach/router"
3+
import { navigate } from "@reach/router"
44
import { isLoggedIn } from "../utils/auth"
55

6-
const PrivateRoute = ({ component: Component, ...rest }) => {
7-
if (!isLoggedIn() && window.location.pathname !== `/app/login`) {
6+
const PrivateRoute = ({ component: Component, location, ...rest }) => {
7+
if (!isLoggedIn() && location.pathname !== `/app/login`) {
88
// If we’re not logged in, redirect to the home page.
99
navigate(`/app/login`)
1010
return null
1111
}
1212

13-
return (
14-
<Router>
15-
<Component {...rest} />
16-
</Router>
17-
)
13+
return <Component {...rest} />
1814
}
1915

2016
PrivateRoute.propTypes = {

examples/simple-auth/src/pages/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import Status from "../components/Status"
1010
const App = () => (
1111
<Layout>
1212
<Status />
13-
<PrivateRoute path="/app/profile" component={Home} />
14-
<PrivateRoute path="/app/details" component={Details} />
1513
<Router>
14+
<PrivateRoute path="/app/profile" component={Home} />
15+
<PrivateRoute path="/app/details" component={Details} />
1616
<Login path="/app/login" />
1717
</Router>
1818
</Layout>

packages/gatsby/cache-dir/loader.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ const queue = {
305305
}
306306
},
307307

308-
getResourcesForPathnameSync: path => pathScriptsCache[path],
308+
getResourcesForPathnameSync: path => {
309+
const page = findPage(path)
310+
return pathScriptsCache[page.path]
311+
},
309312

310313
getResourcesForPathname: path => {
311314
queue.checkIfDoingInitialRenderForSW(path)
@@ -363,6 +366,7 @@ const queue = {
363366
component: syncRequires.components[page.componentChunkName],
364367
page,
365368
}
369+
366370
// Add to the cache.
367371
pathScriptsCache[path] = pageResources
368372
devGetPageData(page.path).then(pageData => {

0 commit comments

Comments
 (0)