navigateTo('/example')}>
+
push('/example')}>
Example
}
diff --git a/packages/gatsby/src/cache-dir/gatsby-browser-entry.js b/packages/gatsby/src/cache-dir/gatsby-browser-entry.js
index 44cea4df05f30..1d7e22d5a9c8f 100644
--- a/packages/gatsby/src/cache-dir/gatsby-browser-entry.js
+++ b/packages/gatsby/src/cache-dir/gatsby-browser-entry.js
@@ -1,6 +1,6 @@
import React from "react"
import PropTypes from "prop-types"
-import Link, { withPrefix, navigateTo } from "gatsby-link"
+import Link, { withPrefix, push, replace, navigateTo } from "gatsby-link"
import pages from "./pages.json"
import loader from "./loader"
import JSONStore from "./json-store"
@@ -48,7 +48,9 @@ StaticQuery.propTypes = {
export {
Link,
withPrefix,
- navigateTo,
+ push,
+ replace,
+ navigateTo, // TODO: remove navigateTo for v3
StaticQueryContext,
StaticQuery,
PageRenderer,
diff --git a/packages/gatsby/src/cache-dir/production-app.js b/packages/gatsby/src/cache-dir/production-app.js
index 837bfc6cce5a5..43326305a4e56 100644
--- a/packages/gatsby/src/cache-dir/production-app.js
+++ b/packages/gatsby/src/cache-dir/production-app.js
@@ -52,7 +52,7 @@ apiRunnerAsync(`onClientEntry`).then(() => {
require(`./register-service-worker`)
}
- const navigateTo = to => {
+ const navigate = (to, replace) => {
const location = createLocation(to, null, null, history.location)
let { pathname } = location
const redirect = redirectMap[pathname]
@@ -73,13 +73,17 @@ apiRunnerAsync(`onClientEntry`).then(() => {
return
}
+ const historyNavigateFunc = replace
+ ? window.___history.replace
+ : window.___history.push
+
// Listen to loading events. If page resources load before
// a second, navigate immediately.
function eventHandler(e) {
if (e.page.path === loader.getPage(pathname).path) {
emitter.off(`onPostLoadPageResources`, eventHandler)
clearTimeout(timeoutId)
- window.___history.push(location)
+ historyNavigateFunc(location)
}
}
@@ -88,13 +92,13 @@ apiRunnerAsync(`onClientEntry`).then(() => {
const timeoutId = setTimeout(() => {
emitter.off(`onPostLoadPageResources`, eventHandler)
emitter.emit(`onDelayedLoadPageResources`, { pathname })
- window.___history.push(location)
+ historyNavigateFunc(location)
}, 1000)
if (loader.getResourcesForPathname(pathname)) {
// The resources are already loaded so off we go.
clearTimeout(timeoutId)
- window.___history.push(location)
+ historyNavigateFunc(location)
} else {
// They're not loaded yet so let's add a listener for when
// they finish loading.
@@ -103,7 +107,8 @@ apiRunnerAsync(`onClientEntry`).then(() => {
}
// window.___loadScriptsForPath = loadScriptsForPath
- window.___navigateTo = navigateTo
+ window.___push = to => navigate(to, false)
+ window.___replace = to => navigate(to, true)
// Call onRouteUpdate on the initial page load.
apiRunner(`onRouteUpdate`, {
diff --git a/packages/gatsby/src/cache-dir/root.js b/packages/gatsby/src/cache-dir/root.js
index 2b18079d36904..08e5e2f156169 100644
--- a/packages/gatsby/src/cache-dir/root.js
+++ b/packages/gatsby/src/cache-dir/root.js
@@ -112,11 +112,16 @@ function shouldUpdateScroll(prevRouterProps, { location: { pathname } }) {
return true
}
-const navigateTo = to => {
+const push = to => {
window.___history.push(to)
}
-window.___navigateTo = navigateTo
+const replace = to => {
+ window.___history.replace(to)
+}
+
+window.___push = push
+window.___replace = replace
const AltRouter = apiRunner(`replaceRouterComponent`, { history })[0]
diff --git a/www/src/components/layout.js b/www/src/components/layout.js
index 2ca7a952c9438..0bf6994e38dca 100644
--- a/www/src/components/layout.js
+++ b/www/src/components/layout.js
@@ -3,7 +3,7 @@ import Modal from "react-modal"
import Helmet from "react-helmet"
import MdClose from "react-icons/lib/md/close"
-import { navigateTo, PageRenderer } from "gatsby"
+import { push, PageRenderer } from "gatsby"
import presets, { colors } from "../utils/presets"
import Navigation from "../components/navigation"
@@ -32,7 +32,7 @@ class DefaultLayout extends React.Component {
}
handleCloseModal() {
- navigateTo(this.props.modalBackgroundPath)
+ push(this.props.modalBackgroundPath)
}
componentDidMount() {
@@ -105,7 +105,7 @@ class DefaultLayout extends React.Component {
backgroundColor: `rgba(255, 255, 255, 0.95)`,
},
}}
- onRequestClose={() => navigateTo(this.props.modalBackgroundPath)}
+ onRequestClose={() => push(this.props.modalBackgroundPath)}
contentLabel="Site Details Modal"
>