Skip to content

Commit

Permalink
fix(plugins/materials): fix new app with no page should not set url p…
Browse files Browse the repository at this point in the history
…age id to undefined (opentiny#1061)
  • Loading branch information
rhlin authored Jan 23, 2025
1 parent 4b9a681 commit 5162ab4
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/plugins/materials/src/composable/useResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,25 @@ const appSchemaState = reactive({
materialsDeps: { scripts: [], styles: new Set() }
})

function goPage(pageId) {
if (!pageId) {
return
}

const url = new URL(window.location)

url.searchParams.set('pageid', pageId)
window.history.pushState({}, '', url)
usePage().postLocationHistoryChanged({ pageId })
}

const initPage = (pageInfo) => {
try {
if (pageInfo.meta) {
const { occupier } = pageInfo.meta

useLayout().layoutState.pageStatus = getCanvasStatus(occupier)
goPage(pageInfo.meta?.id)
} else {
useLayout().layoutState.pageStatus = {
state: 'empty',
Expand All @@ -54,12 +67,6 @@ const initPage = (pageInfo) => {
pageInfo.id = pageInfo.meta?.id
} catch (error) {
console.log(error) // eslint-disable-line
} finally {
const url = new URL(window.location)

url.searchParams.set('pageid', pageInfo.id)
window.history.pushState({}, '', url)
usePage().postLocationHistoryChanged({ pageId: pageInfo.id })
}

const { id, meta, ...pageSchema } = pageInfo
Expand Down

0 comments on commit 5162ab4

Please sign in to comment.