Vue Router Flashcards

1
Q

Qué es Vue Router

A

Vue Router is the official router for Vue.js (opens new window). It deeply integrates with Vue.js core to make building Single Page Applications with Vue.js a breeze. Features include:

Nested route/view mapping
Modular, component-based router configuration
Route params, query, wildcards
View transition effects powered by Vue.js’ transition system
Fine-grained navigation control
Links with automatic active CSS classes
HTML5 history mode or hash mode, with auto-fallback in IE9
Customizable Scroll Behavior

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Crear Proyecto

A

Elegir la opción de Vue Router en el CLI de vue.

Tendremos dos carpetas adicionales, las cuales son “router” y “views”

router: Archivo de configuración de rutas
views: Almacena todos los componentes que se comportarán como componentes padres de nuestras vistas

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

router-link

A

Es el componente para permitir la navegación del usuario.
La ubicación de destino se especifica con el atributo to

<div>
Home |
About
</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

router-view

A

ver

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

router/index.js

A

import { createRouter, createWebHistory } from ‘vue-router’
import Home from ‘../views/Home.vue’

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})

export default router

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Vistas vs Componentes

A

No confundir con componentes, estos siguen cumpliendo su función principal que es encapsular nuestra lógica y hacerla reutilizable. Aunque son practiamente lo mismo que las vistas, es para manter un orden en nuestro trabajo.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Rutas con parámetros

A

Configurar router/index.js
{
path: ‘/blog/:id’,
name: ‘Articulo’,
component: () => import(/* webpackChunkName: “about” */ ‘../views/Articulo.vue’)
}
Visitar /blog/1 y cargará vista Articulo.vue

<h2>Parámetro: {{ $route.params.id }}</h2>

https://bluuweb.github.io/vue-udemy/03-router/#rutas-con-parametros

How well did you know this?
1
Not at all
2
3
4
5
Perfectly