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:
parent
5ebb943c84
commit
349608fe49
|
@ -7,6 +7,13 @@ import PQueue from '../p-queue'
|
||||||
import { loadGetInitialProps, getURL, warn, execOnce } from '../utils'
|
import { loadGetInitialProps, getURL, warn, execOnce } from '../utils'
|
||||||
import { _rewriteUrlForNextExport } from './'
|
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 {
|
export default class Router {
|
||||||
constructor (pathname, query, as, { pageLoader, Component, ErrorComponent, err } = {}) {
|
constructor (pathname, query, as, { pageLoader, Component, ErrorComponent, err } = {}) {
|
||||||
// represents the current component key
|
// represents the current component key
|
||||||
|
@ -185,9 +192,17 @@ export default class Router {
|
||||||
}
|
}
|
||||||
|
|
||||||
changeState (method, url, as, options = {}) {
|
changeState (method, url, as, options = {}) {
|
||||||
if (window.frameElement) {
|
if (typeof window.history === 'undefined') {
|
||||||
execOnce(warn)(`Warning: You're using Next.js inside an iFrame. Browser history is disabled.`)
|
historyUnavailableWarning()
|
||||||
} else if (method !== 'pushState' || getURL() !== as) {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof window.history[method] === 'undefined') {
|
||||||
|
historyMethodWarning(method)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method !== 'pushState' || getURL() !== as) {
|
||||||
window.history[method]({ url, as, options }, null, as)
|
window.history[method]({ url, as, options }, null, as)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue