Skip to content

Commit

Permalink
have routing with parameters working
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfgebhardt committed Nov 23, 2023
1 parent fedeaca commit 1937776
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion renderer/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function createApp(pageContext: VikePageContext & PageContext, isClient = true)

objectAssign(app, {
changePage: (pageContext: VikePageContext & PageContext) => {
Object.assign(pageContextReactive, reactive(pageContext))
Object.assign(pageContextReactive, pageContext)
rootComponent.Page = markRaw(pageContext.Page)
rootComponent.pageProps = markRaw(pageContext.pageProps || {})
},
Expand Down
4 changes: 2 additions & 2 deletions src/pages/app/index.page.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default (pageContext: PageContext) => {
}
}

const result = resolveRoute('/app/@id', pageContext.urlPathname)
if (!['inc', 'reset'].includes(result.routeParams.id)) {
const result = resolveRoute('/app/@page', pageContext.urlPathname)
if (!['inc', 'reset'].includes(result.routeParams.page)) {
return false
}
return result
Expand Down
13 changes: 13 additions & 0 deletions src/pages/app/index.page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { PageContextBuiltInServer } from 'vike/types'

export { onBeforeRender }

async function onBeforeRender(pageContext: PageContextBuiltInServer) {
const { page } = pageContext.routeParams
const pageProps = { page }
return {
pageContext: {
pageProps,
},
}
}
12 changes: 1 addition & 11 deletions src/pages/app/index.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<v-list-item link title="Increase" :active="page === 'inc'" href="/app/inc"></v-list-item>

<v-divider class="my-2"></v-divider>

<v-list-item link title="Reset" :active="page === 'reset'" href="/app/reset"></v-list-item>
</v-list>
</template>
Expand All @@ -31,18 +30,9 @@
</template>

<script lang="ts" setup>
import { usePageContext } from '#context/usePageContext'
import DefaultLayout from '#layouts/DefaultLayout.vue'
import { useCounterStore } from '#stores/counter'
const counter = useCounterStore()
/*
const {
routeParams: { id: page },
} = usePageContext()
*/
const { routeParams } = usePageContext()
const page = routeParams?.id
// console.log(page)
defineProps(['page'])
</script>

0 comments on commit 1937776

Please sign in to comment.