Browse Source

Fix popstate client routing events

gh-pages
Andrew Kingston 6 years ago
parent
commit
c627c1d7d7
  1. 31
      packages/client/src/render/screenRouter.js

31
packages/client/src/render/screenRouter.js

@ -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 isRunningLocally = () => {
const hostname = (window.location && window.location.hostname) || ""
return (
hostname === "localhost" ||
hostname === "127.0.0.1" ||
hostname.startsWith("192.168")
)
}
const makeRootedPath = url => { const makeRootedPath = url => {
const hostname = window.location && window.location.hostname if (isRunningLocally()) {
if (hostname) { const appId = parseAppIdFromCookie(window.document.cookie)
if ( if (url) {
hostname === "localhost" || if (!url.startsWith("/")) {
hostname === "127.0.0.1" || url = `/${url}`
hostname.startsWith("192.168") }
) { if (url.startsWith(`/${appId}`)) {
const appId = parseAppIdFromCookie(window.document.cookie) return url
if (url) {
if (url.startsWith(appId)) return url
return `/${appId}${url.startsWith("/") ? "" : "/"}${url}`
} }
return appId return `/${appId}${url}`
} }
return `/${appId}`
} }
return url return url
} }

Loading…
Cancel
Save