Fix popstate client routing events

This commit is contained in:
Andrew Kingston 2020-10-16 09:16:25 +01:00
parent 89bba530be
commit 92a6bd1a6d
1 changed files with 19 additions and 12 deletions

View File

@ -3,21 +3,28 @@ import appStore from "../state/store"
import { parseAppIdFromCookie } from "./getAppId" import { parseAppIdFromCookie } from "./getAppId"
export const screenRouter = ({ screens, onScreenSelected, window }) => { export const screenRouter = ({ screens, onScreenSelected, window }) => {
const makeRootedPath = url => { const isRunningLocally = () => {
const hostname = window.location && window.location.hostname const hostname = (window.location && window.location.hostname) || ""
if (hostname) { return (
if (
hostname === "localhost" || hostname === "localhost" ||
hostname === "127.0.0.1" || hostname === "127.0.0.1" ||
hostname.startsWith("192.168") hostname.startsWith("192.168")
) { )
}
const makeRootedPath = url => {
if (isRunningLocally()) {
const appId = parseAppIdFromCookie(window.document.cookie) const appId = parseAppIdFromCookie(window.document.cookie)
if (url) { if (url) {
if (url.startsWith(appId)) return url if (!url.startsWith("/")) {
return `/${appId}${url.startsWith("/") ? "" : "/"}${url}` url = `/${url}`
} }
return appId if (url.startsWith(`/${appId}`)) {
return url
} }
return `/${appId}${url}`
}
return `/${appId}`
} }
return url return url
} }