some more routing fixes - css now loaded at runtime

This commit is contained in:
Michael Shanks 2020-02-21 16:52:29 +00:00
parent 5b1bbad6c6
commit ec7cc028c5
4 changed files with 23 additions and 5 deletions

View File

@ -50,7 +50,11 @@ export const createApp = (
onScreenSelected, onScreenSelected,
frontendDefinition.appRootPath frontendDefinition.appRootPath
) )
routeTo(currentUrl || window.location.pathname) const fallbackPath = window.location.pathname.replace(
frontendDefinition.appRootPath,
""
)
routeTo(currentUrl || fallbackPath)
} }
const attachChildrenParams = stateManager => { const attachChildrenParams = stateManager => {

View File

@ -2,7 +2,13 @@ import regexparam from "regexparam"
import { writable } from "svelte/store" import { writable } from "svelte/store"
export const screenRouter = (screens, onScreenSelected, appRootPath) => { export const screenRouter = (screens, onScreenSelected, appRootPath) => {
const makeRootedPath = url => (appRootPath ? `${appRootPath}/${url}` : url) const makeRootedPath = url => {
if (appRootPath) {
if (url) return `${appRootPath}${url.startsWith("/") ? "" : "/"}${url}`
return appRootPath
}
return url
}
const routes = screens.map(s => makeRootedPath(s.route)) const routes = screens.map(s => makeRootedPath(s.route))
let fallback = routes.findIndex(([p]) => p === "*") let fallback = routes.findIndex(([p]) => p === "*")

View File

@ -231,8 +231,14 @@ module.exports = (config, app) => {
await next() await next()
} else if (path.startsWith("/_shared/")) { } else if (path.startsWith("/_shared/")) {
await send(ctx, path.replace(`/_shared/`, ""), { root: ctx.sharedPath }) await send(ctx, path.replace(`/_shared/`, ""), { root: ctx.sharedPath })
} else { } else if (
path.endsWith(".js") ||
path.endsWith(".map") ||
path.endsWith(".css")
) {
await send(ctx, path, { root: ctx.publicPath }) await send(ctx, path, { root: ctx.publicPath })
} else {
await send(ctx, "/index.html", { root: ctx.publicPath })
} }
}) })
.use(async (ctx, next) => { .use(async (ctx, next) => {

View File

@ -11,6 +11,8 @@
html, body { html, body {
height: 100%; height: 100%;
width: 100%; width: 100%;
margin: 0px;
padding: 0px;
} }
</style> </style>
@ -19,11 +21,11 @@
{{ /each }} {{ /each }}
{{ each(options.screenStyles) }} {{ each(options.screenStyles) }}
<link rel='stylesheet' href='{{ @this }}'> <link rel='stylesheet' href='{{ appRootPath }}{{ @this }}'>
{{ /each }} {{ /each }}
{{ if(options.pageStyle) }} {{ if(options.pageStyle) }}
<link rel='stylesheet' href='{{ pageStyle }}'> <link rel='stylesheet' href='{{ appRootPath }}{{ pageStyle }}'>
{{ /if }} {{ /if }}