restricting parameters #216
-
Backgroundmeta frameworks like svelte kit allow you to define a matcher for params in your page if you want to show a page only for certain routes. Given a directory structure like this
I want to restrict the possible parameters for both vegetable and fruit, to not accidentally show the wrong page. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You use <script setup lang="ts>
definePage({
path: '/:fruit(watermelon|strawberry)',
})
</script> If the match is more complex, you will need to setup a navigation guard so you can freely do any check: <script setup>
definePage({
beforeEnter(to) {
if (Number.isNaN(Number(to.params.id))) {
console.log('invalid param id', to.params.id)
return false
}
},
})
<script> |
Beta Was this translation helpful? Give feedback.
You use
definePage()
to override thepath
and override the regexp of the parameter:If the match is more complex, you will need to setup a navigation guard so you can freely do any check: