Sample questions
Question 1Easy
Which navigation guard runs before every navigation globally?
- router.afterAll
- router.beforeEach
- router.onEnter
- router.guard
Answer: B. router.beforeEach
Explanation
beforeEach((to, from) => ...) can return false or a location to cancel or redirect.
Step-by-step solution
- Register beforeEach.
- Return a result.
Why the other options are wrong
- A.
router.afterAll is not a Vue API for this; the correct choice is router.beforeEach. - C.
router.onEnter is not a Vue API for this; the correct choice is router.beforeEach. - D.
router.guard is not a Vue API for this; the correct choice is router.beforeEach.
Question 2Easy
Which Vue Router component renders the component matched by the current route?
- <RouterView>
- <RouterLink>
- <RouteOutlet>
- <Component>
Answer: A. <RouterView>
Explanation
<RouterView> is the placeholder where matched route components appear.
Step-by-step solution
- RouterView is the placeholder in the template where the matched route's component is shown.
- It renders whichever component matches the current route.
- So the component is RouterView (option A).
Why the other options are wrong
- B. RouterLink creates navigation links, not the route's content.
- C. RouteOutlet is not a Vue Router component.
- D. Component is a dynamic component tag, not a Vue Router placeholder.
Tip: RouterView goes where the page content should appear; RouterLink goes on navigation items.
Question 3Easy
Which component is used to create navigation links in Vue Router that avoid full page reloads?
- <RouterLink>
- <a href>
- <NavTo>
- <RouterView>
Answer: A. <RouterLink>
Explanation
<RouterLink to="/about"> navigates client-side.
Step-by-step solution
- RouterLink is the Vue Router component for navigation links.
- It changes the route on the client, without a full page reload.
- So the component for navigation links is RouterLink (option A).
Why the other options are wrong
- B. A plain a tag with href causes a full page load.
- C. NavTo is not a Vue Router component.
- D. RouterView displays the matched component; it is not a link.
Tip: Use RouterLink for internal links so navigation stays inside the app.
Question 4Easy
Which component renders the route's matched component?
- <RouteOutlet>
- <RouterView>
- <ViewPort>
- <RouterLink>
Answer: B. <RouterView>
Explanation
RouterView is the placeholder for route components.
Step-by-step solution
- Place RouterView.
- Matched view appears.
Why the other options are wrong
- A. Angular name.
- C. ViewPort is not a Vue Router component; RouterView renders the matched route.
- D. RouterLink creates links.
Question 5Medium
What does a Pinia store created with defineStore return?
- The store directly, so you can import and use it without calling any function
- A Vuex module
- A function (e.g. useCounterStore) that returns the store instance
- A plain object
Answer: C. A function (e.g. useCounterStore) that returns the store instance
Explanation
Calling the returned useXStore() inside components yields the singleton store.
Step-by-step solution
- defineStore returns a hook.
- Call it to get the store.
Why the other options are wrong
- A. It returns a hook.
- B. Different library.
- D. It is a reactive store.
Question 6Medium
What does router.push('/home') do versus router.replace('/home')?
- push swaps the current entry and replace adds a new one, so Back works in reverse
- Both reload the page
- push adds a history entry; replace swaps the current one
- Both do nothing for same path
Answer: C. push adds a history entry; replace swaps the current one
Explanation
After replace, the Back button skips the replaced entry.
Step-by-step solution
- push adds history.
- replace overwrites it.
Why the other options are wrong
- A. Reversed.
- B. SPA navigation does not reload.
- D. Navigation still happens or duplicates are handled.
Question 7Medium
In a Pinia setup store, what plays the role of state and getters?
- data and methods
- this.state
- mutations
- ref() and computed()
Answer: D. ref() and computed()
Explanation
Setup stores use refs for state, computeds for getters and functions for actions.
Step-by-step solution
- Define refs.
- Define computeds.
- Return them.
Why the other options are wrong
- A. Options API names.
- B. A setup store does not use this.state; state is declared with ref().
- C. Pinia has no mutations.
Question 8Medium
Which library is the official state management store for Vue 3?
- Redux
- Pinia
- MobX
- Flux
Answer: B. Pinia
Explanation
Pinia is the official store library for Vue; Vuex is the older one.
Step-by-step solution
- Pinia is the official state management library for Vue 3.
- Vuex is the older store library.
- So the official store for Vue 3 is Pinia (option B).
Why the other options are wrong
- A. Redux is a React-focused library, not the official Vue store.
- C. MobX is a separate state library, not the official Vue store.
- D. Flux is an architecture pattern, not the official Vue store.
Tip: Pinia is the default choice for shared state in Vue 3.
Question 9Hard
Why does destructuring a Pinia store lose reactivity, and what is the fix?
- Primitive state is copied; use storeToRefs(store)
- Stores are frozen after creation, so you must clone them before reading properties
- Destructuring is blocked; use watch
- Use Object.assign
Answer: A. Primitive state is copied; use storeToRefs(store)
Explanation
storeToRefs produces refs for state and getters; actions can be destructured directly.
Step-by-step solution
- Destructure copies value.
- Use storeToRefs.
Why the other options are wrong
- B. They are not frozen.
- C. It is allowed but not reactive.
- D. That also copies.
Question 10Hard
The component for /user/1 shows the same instance when going to /user/2. How do you react?
- Watch route.params.id (or use onBeforeRouteUpdate)
- Use onMounted only, because it runs each time the route parameters change
- Reload the page
- Use a v-if on the router
Answer: A. Watch route.params.id (or use onBeforeRouteUpdate)
Explanation
Vue Router reuses the component for the same route record, so mounted does not run again.
Step-by-step solution
- Instance reused.
- Watch params.
Why the other options are wrong
- B. It will not run again; the instance is reused.
- C. Defeats the SPA.
- D. Does not detect param changes.
Practise all 15 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →