Skip to content

Commit

Permalink
fix: bug where client routes are redirected to their base page path (#…
Browse files Browse the repository at this point in the history
…8083)

* fix: bug where client routes are redirected to their base page path

* address feedback

* fix location
  • Loading branch information
jquense authored and pieh committed Sep 12, 2018
1 parent b3bab8e commit 4cd37ea
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/gatsby/cache-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { apiRunner, apiRunnerAsync } from "./api-runner-browser"
import React, { createElement } from "react"
import ReactDOM from "react-dom"
import { Router, navigate } from "@reach/router"
import { match } from "@reach/router/lib/utils"
import { ScrollContext } from "gatsby-react-router-scroll"
import domReady from "domready"
import {
Expand Down Expand Up @@ -80,37 +81,37 @@ apiRunnerAsync(`onClientEntry`).then(() => {
}
}

const { page, location: browserLoc } = window
// TODO: comment what this check does
if (
window.page &&
window.page.path !== `/404.html` &&
!window.page.path.match(/^\/offline-plugin-app-shell-fallback\/?$/) &&
__PATH_PREFIX__ + window.page.path !== window.location.pathname
page &&
page.path !== `/404.html` &&
__PATH_PREFIX__ + page.path !== browserLoc.pathname &&
!page.path.match(/^\/offline-plugin-app-shell-fallback\/?$/) &&
(!page.matchPath ||
!match(__PATH_PREFIX__ + page.matchPath, browserLoc.pathname))
) {
navigate(
__PATH_PREFIX__ +
window.page.path +
window.location.search +
window.location.hash,
__PATH_PREFIX__ + page.path + browserLoc.search + browserLoc.hash,
{ replace: true }
)
}

loader
.getResourcesForPathname(window.location.pathname)
.getResourcesForPathname(browserLoc.pathname)
.then(() => {
if (!loader.getPage(window.location.pathname)) {
if (!loader.getPage(browserLoc.pathname)) {
return loader
.getResourcesForPathname(`/404.html`)
.then(resources =>
loadDirectlyOr404(
resources,
window.location.pathname +
window.location.search +
window.location.hash,
browserLoc.pathname + browserLoc.search + browserLoc.hash,
true
)
)
}
return null
})
.then(() => {
const Root = () =>
Expand Down

0 comments on commit 4cd37ea

Please sign in to comment.