Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)}
)
}
}
const { page, location: browserLoc } = window
if (
// Make sure the window.page object is defined
page &&
// The canonical path doesn't match the actual path (i.e. the address bar)
__PATH_PREFIX__ + page.path !== browserLoc.pathname &&
// ...and if matchPage is specified, it also doesn't match the actual path
(!page.matchPath ||
!match(__PATH_PREFIX__ + page.matchPath, browserLoc.pathname)) &&
// Ignore 404 pages, since we want to keep the same URL
page.path !== `/404.html` &&
!page.path.match(/^\/404\/?$/) &&
// Also ignore the offline shell (since when using the offline plugin, all
// pages have this canonical path)
!page.path.match(/^\/offline-plugin-app-shell-fallback\/?$/)
) {
navigate(
__PATH_PREFIX__ + page.path + browserLoc.search + browserLoc.hash,
{ replace: true }
)
}
loader
.getResourcesForPathname(browserLoc.pathname)
.then(resources => {
pages.some(page => {
let pathToMatch = page.matchPath ? page.matchPath : page.path
if (matchPath(pathToMatch, trimmedPathname)) {
foundPage = page
pageCache[trimmedPathname] = page
return true
}
// Finally, try and match request with default document.
if (matchPath(`${page.path}index.html`, trimmedPathname)) {
foundPage = page
pageCache[trimmedPathname] = page
return true
}
return false
})
pages.some(page => {
let pathToMatch = page.matchPath ? page.matchPath : page.path
if (matchPath(pathToMatch, trimmedPathname)) {
foundPage = page
pageCache[trimmedPathname] = page
return true
}
// Finally, try and match request with default document.
if (matchPath(`${page.path}index.html`, trimmedPathname)) {
foundPage = page
pageCache[trimmedPathname] = page
return true
}
return false
})
export const findMatchPath = rawPathname => {
const trimmedPathname = cleanPath(rawPathname)
for (const { matchPath, path } of matchPaths) {
if (match(matchPath, trimmedPathname)) {
return normalizePagePath(path)
}
}
return null
}