1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Do feature detection instead of disabling iframes. (#3880)

This commit is contained in:
Tim Neutkens 2018-02-25 15:19:38 +01:00 committed by Arunoda Susiripala
parent 5ebb943c84
commit 349608fe49

View file

@ -7,6 +7,13 @@ import PQueue from '../p-queue'
import { loadGetInitialProps, getURL, warn, execOnce } from '../utils'
import { _rewriteUrlForNextExport } from './'
const historyUnavailableWarning = execOnce(() => {
warn(`Warning: window.history is not available.`)
})
const historyMethodWarning = execOnce((method) => {
warn(`Warning: window.history.${method} is not available`)
})
export default class Router {
constructor (pathname, query, as, { pageLoader, Component, ErrorComponent, err } = {}) {
// represents the current component key
@ -185,9 +192,17 @@ export default class Router {
}
changeState (method, url, as, options = {}) {
if (window.frameElement) {
execOnce(warn)(`Warning: You're using Next.js inside an iFrame. Browser history is disabled.`)
} else if (method !== 'pushState' || getURL() !== as) {
if (typeof window.history === 'undefined') {
historyUnavailableWarning()
return
}
if (typeof window.history[method] === 'undefined') {
historyMethodWarning(method)
return
}
if (method !== 'pushState' || getURL() !== as) {
window.history[method]({ url, as, options }, null, as)
}
}