Question 29
Answer the given Subquestions:
Consider the following Vue Router configuration in a Vue 2 application:
const routes = [ { path: '/', name: 'Home', component: HomeView }, { path: '/user/:id', name: 'UserProfile', component: UserProfile }, { path: '/product/:category/:id', name: 'ProductDetail', component: ProductDetail }];In a Vue component, you have these navigation methods:
<template> <div> <button @click="goToUser">View User</button> <button @click="goToProduct">View Product</button> <router-link :to="{ name: 'Home' }">Home</router-link> </div></template>
<script>export default { methods: { goToUser() { this.$router.push({ name: 'UserProfile', params: { id: 123 } }); }, goToProduct() { this.$router.push({ name: 'ProductDetail', params: { category: 'electronics', id: 456} }); }, navigateOne() { this.$router.push({ name: 'UserProfile', params: { id: 555 }, query: { tab: 'settings'} }); }, navigateTwo() { this.$router.replace({ name: 'Home' }); }, goBack() { this.$router.go(-1); }}</script>What URLs will be generated when the user clicks each navigation element?
User button: /user,
Product button: /product,
Home link: /homeUser button: /user/123,
Product button: /product/electronics/456,
Home link: /User button: /UserProfile/123,
Product button: /ProductDetail/electronics/456,
Home link: /HomeUser button: /user?id=123,
Product button: /product?category=electronics&id=456,
Home link: /