N
Nuxt7mo ago
tsi-trevor

How can I remove a route parameter value?

Say I have a route /foo/:bar? that is distinct (at least by what's rendered on the page) from /foo. How can I clear :bar and cause a redirect? My current attempt looks like this:
/** Currently at /foo/buzz */
const router = useRouter()

/** To be triggered by some event */
const foo = () => router.replace({ params: { bar: null } })
/** Currently at /foo/buzz */
const router = useRouter()

/** To be triggered by some event */
const foo = () => router.replace({ params: { bar: null } })
2 Replies
manniL
manniL7mo ago
Spotaneous idea
const { bar: _unused , ...newParams } = useRoute.params()

router.replace({ params: newParams })
const { bar: _unused , ...newParams } = useRoute.params()

router.replace({ params: newParams })
Mads
Mads7mo ago
or navigateTo({ path: ‘/foo’}) Remember to use await or return
Want results from more Discord servers?
Add your server