Skip to content
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/simple-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"author": "Jason Lengstorf <[email protected]>",
"dependencies": {
"gatsby": "next",
"gatsby": "^2.0.0-beta.91",
"gatsby-plugin-react-helmet": "next",
"prop-types": "^15.6.1",
"react": "^16.4.0",
Expand Down
12 changes: 4 additions & 8 deletions examples/simple-auth/src/components/PrivateRoute.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import React from "react"
import PropTypes from "prop-types"
import { Router, navigate } from "@reach/router"
import { navigate } from "@reach/router"
import { isLoggedIn } from "../utils/auth"

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

return (
<Router>
<Component {...rest} />
</Router>
)
return <Component {...rest} />
}

PrivateRoute.propTypes = {
Expand Down
4 changes: 2 additions & 2 deletions examples/simple-auth/src/pages/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Status from "../components/Status"
const App = () => (
<Layout>
<Status />
<PrivateRoute path="/app/profile" component={Home} />
<PrivateRoute path="/app/details" component={Details} />
<Router>
<PrivateRoute path="/app/profile" component={Home} />
<PrivateRoute path="/app/details" component={Details} />
<Login path="/app/login" />
</Router>
</Layout>
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby/cache-dir/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ const queue = {
}
},

getResourcesForPathnameSync: path => pathScriptsCache[path],
getResourcesForPathnameSync: path => {
const page = findPage(path)
return pathScriptsCache[page.path]
},

getResourcesForPathname: path => {
queue.checkIfDoingInitialRenderForSW(path)
Expand Down Expand Up @@ -363,6 +366,7 @@ const queue = {
component: syncRequires.components[page.componentChunkName],
page,
}

// Add to the cache.
pathScriptsCache[path] = pageResources
devGetPageData(page.path).then(pageData => {
Expand Down