import React from "react" import { Router, Location, BaseContext } from "@gatsbyjs/reach-router" import { ScrollContext } from "gatsby-react-router-scroll" import { shouldUpdateScroll, RouteUpdates } from "./navigation" import { apiRunner } from "./api-runner-browser" import loader from "./loader" import { PageQueryStore, StaticQueryStore } from "./query-result-store" import EnsureResources from "./ensure-resources" import FastRefreshOverlay from "./fast-refresh-overlay" // In gatsby v2 if Router is used in page using matchPaths // paths need to contain full path. // For example: // - page have `/app/*` matchPath // - inside template user needs to use `/app/xyz` as path // Resetting `basepath`/`baseuri` keeps current behaviour // to not introduce breaking change. // Remove this in v3 const RouteHandler = props => ( ) class LocationHandler extends React.Component { render() { const { location } = this.props if (!loader.isPageNotFound(location.pathname)) { return ( {locationAndPageResources => ( )} ) } const dev404PageResources = loader.loadPageSync(`/dev-404-page`) const real404PageResources = loader.loadPageSync(`/404.html`) let custom404 if (real404PageResources) { custom404 = ( ) } return ( ) } } const Root = () => ( {locationContext => } ) // Let site, plugins wrap the site e.g. for Redux. const rootWrappedWithWrapRootElement = apiRunner( `wrapRootElement`, { element: }, , ({ result, plugin }) => { return { element: result } } ).pop() function RootWrappedWithOverlayAndProvider() { return ( {rootWrappedWithWrapRootElement} ) } export default RootWrappedWithOverlayAndProvider