Consider a Vue 3 app using Vue Router. The router has only two routes defined: '/' and '/about'. What will the app display if the user navigates to '/contact'?
import { createRouter, createWebHistory } from 'vue-router'; import Home from './components/Home.vue'; import About from './components/About.vue'; const routes = [ { path: '/', component: Home }, { path: '/about', component: About } ]; const router = createRouter({ history: createWebHistory(), routes }); export default router;
Think about what Vue Router does when no route matches the URL.
If a user navigates to a path not defined in the router, Vue Router does not render any component, resulting in a blank page. It does not redirect or throw an error by default.
You want to add Vue Router to your Vue 3 app. Which code snippet correctly sets up the router and integrates it with the app?
Remember the order: create app, use plugins, then mount.
You must call app.use(router) before mounting the app. Option D does this correctly. Option D mounts before using router, so router won't work. Option D tries chaining use and mount which is valid in Vue 3. Option D calls router.use(app) which is not a Vue Router method.
In a Vue 3 app with Vue Router, you run router.push('/dashboard'). What will this.$route.path be immediately after?
import { createRouter, createWebHistory } from 'vue-router'; const routes = [{ path: '/dashboard', component: {} }]; const router = createRouter({ history: createWebHistory(), routes }); // Assume inside a component method: async function navigate() { await router.push('/dashboard'); console.log(this.$route.path); }
Think about what router.push does and when $route updates.
After await router.push('/dashboard'), the route changes and this.$route.path reflects the new path '/dashboard'.
Look at this router setup code. The app shows a blank page on navigation. What is the cause?
import { createRouter, createWebHistory } from 'vue-router'; import Home from './Home.vue'; const routes = [ { path: '/', component: Home } ]; const router = createRouter({ history: createWebHistory('/app/'), routes }); export default router;
Check if the history base matches the app's deployment path.
If the base URL in createWebHistory does not match the app's actual base path, Vue Router cannot match routes correctly, resulting in a blank page. The other options are incorrect because the component is imported, routes exist, and passing a base string is valid.
Choose the correct statement about createWebHistory in Vue Router.
Think about how URLs look and what the server needs to do.
createWebHistory uses the browser's History API to create clean URLs without hashes. This requires the server to be configured to serve the app's index.html for all routes to avoid 404 errors. It does not fallback automatically, does not use hashes, and does not disable navigation buttons.