Fix unrecoverable crash when the screen URL param is not a valid screen
This commit is contained in:
parent
67e8490eac
commit
fbe15ccfd9
|
@ -1,6 +1,6 @@
|
|||
<script>
|
||||
import { onMount } from "svelte"
|
||||
import { params, leftover } from "@sveltech/routify"
|
||||
import { params, leftover, goto } from "@sveltech/routify"
|
||||
import { store } from "builderStore"
|
||||
|
||||
// Get any leftover params not caught by Routifys params store.
|
||||
|
@ -8,17 +8,30 @@
|
|||
|
||||
// It's a screen, set it to that screen
|
||||
if ($params.screen !== "page-layout") {
|
||||
store.setCurrentScreen(decodeURI($params.screen))
|
||||
const currentScreenName = decodeURI($params.screen)
|
||||
const validScreen =
|
||||
$store.screens.findIndex(
|
||||
screen => screen.props._instanceName === currentScreenName
|
||||
) !== -1
|
||||
|
||||
// There are leftover stuff, like IDs, so navigate the components and find the ID and select it.
|
||||
if ($leftover) {
|
||||
// Get the correct screen children.
|
||||
const screenChildren = $store.pages[$params.page]._screens.find(
|
||||
screen =>
|
||||
screen.props._instanceName === $params.screen ||
|
||||
screen.props._instanceName === decodeURIComponent($params.screen)
|
||||
).props._children
|
||||
findComponent(componentIds, screenChildren)
|
||||
if (!validScreen) {
|
||||
// Go to main layout if URL set to invalid screen
|
||||
store.setCurrentPage("main")
|
||||
$goto("../../main")
|
||||
} else {
|
||||
// Otherwise proceed to set screen
|
||||
store.setCurrentScreen(currentScreenName)
|
||||
|
||||
// There are leftover stuff, like IDs, so navigate the components and find the ID and select it.
|
||||
if ($leftover) {
|
||||
// Get the correct screen children.
|
||||
const screenChildren = $store.pages[$params.page]._screens.find(
|
||||
screen =>
|
||||
screen.props._instanceName === $params.screen ||
|
||||
screen.props._instanceName === decodeURIComponent($params.screen)
|
||||
).props._children
|
||||
findComponent(componentIds, screenChildren)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// It's a page, so set the screentype to page.
|
||||
|
|
Loading…
Reference in New Issue