Vue · Middle · Question 62 of 75

How do you keep filters in the URL query and react to their changes?

const route = useRoute()
watch(() => route.query.status, (status) => load(status))
router.push({ query: { ...route.query, status: 'open' } })

Explanation

URL state survives reloads and can be shared. Query values are strings (or arrays) and need parsing.

Further reading

Problem with a question

Vue · Middle · question 62

Test yourself

Take the Vue · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz