Router Configuration
The router is configured insrc/router/index.js:
src/router/index.js
Route Definitions
/ - Home
/ - Home
Name:
homeComponent: HomeView.vueLanding page of the application./about - About
/about - About
Name:
aboutComponent: AboutView.vueInformation about the application./pokemons - Pokemon List
/pokemons - Pokemon List
Name:
pokemonsComponent: PokemonsView.vueMain Pokedex view with searchable, paginated Pokemon list./favoritos - Favorites
/favoritos - Favorites
Name:
favoritosComponent: FavoritosView.vueDisplay user’s favorite Pokemon from the Pinia store./pokemons/:nombre - Pokemon Detail
/pokemons/:nombre - Pokemon Detail
Name:
pokeComponent: PokeView.vueDynamic Parameter: :nombre - Pokemon nameDisplays detailed information for a specific Pokemon including stats, abilities, and moves.Example: /pokemons/pikachu/pokemons/PokeNotFound - Pokemon Not Found
/pokemons/PokeNotFound - Pokemon Not Found
Name:
PokeNotFoundComponent: PokeNotFountView.vueError page when a Pokemon cannot be found./pokemons/ability/:habilidad - Pokemon by Ability
/pokemons/ability/:habilidad - Pokemon by Ability
Name:
habilidadComponent: HabilidadView.vueDynamic Parameter: :habilidad - Ability nameShows all Pokemon with a specific ability.Example: /pokemons/ability/overgrow/* - 404 Not Found
/* - 404 Not Found
Name:
NotFoundComponent: NotFoundView.vuePattern: :pathMatch(.*)*Catch-all route for undefined paths.Lazy Loading
All routes use dynamic imports for code splitting:Benefits
- Faster initial load - Only the required route code is loaded
- Smaller bundles - Each route generates a separate chunk
- Better performance - Routes are loaded on-demand when visited
Navigation in Components
The application uses Vue Router’s composition API and component features:Using RouterLink
Dynamic Route Links
src/views/PokemonsView.vue
Accessing Route Parameters
src/views/PokeView.vue
Programmatic Navigation
History Mode
The router uses HTML5 History mode:History Mode
- Clean URLs without hash (
#) - Uses browser’s History API
- Requires server configuration for SPA fallback
- Better SEO compared to hash mode
Route Examples
| Route | Description | Example |
|---|---|---|
/ | Home page | N/A |
/pokemons | Pokemon list | N/A |
/pokemons/:nombre | Pokemon detail | /pokemons/charizard |
/pokemons/ability/:habilidad | Pokemon by ability | /pokemons/ability/blaze |
/favoritos | Favorites | N/A |
/* | 404 error | /invalid-path |
Best Practices
Use Named Routes
Use Named Routes
Named routes are more maintainable than path strings:
Validate Route Parameters
Validate Route Parameters
Always validate dynamic parameters before using them:
Handle Loading States
Handle Loading States
Show loading indicators when fetching route data:
Next Steps
State Management
Learn about Pinia stores for global state
Composables
Explore reusable composition functions