提交 349608fe 编写于 作者: T Tim Neutkens 提交者: Arunoda Susiripala

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

上级 5ebb943c
......@@ -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)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册