Skip to main content

Overview

The Biométrico application uses Vue Router for client-side navigation. The router is configured with web history mode and defines routes for authentication, photo management, and individual registration. Source: src/router/index.js

Router Configuration

The router is created using createWebHistory mode:
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
Source: src/router/index.js:62-65

Configuration Details

history
RouterHistory
Uses HTML5 history mode with the base URL from process.env.BASE_URL. This provides clean URLs without hash fragments.
routes
RouteRecordRaw[]
Array of route definitions (see below)

Route Definitions

Login Route

The application entry point for authentication.
{
  path: '/',
  name: 'login',
  component: Login
}
Source: src/router/index.js:12-16
path
string
/ - Root path of the application
name
string
login - Route name for programmatic navigation
component
Component
Login - Component from src/views/Login/Signin.vue
Usage:
this.$router.push('/');
// or
this.$router.push({ name: 'login' });

Home Route

Main dashboard after authentication.
{
  path: '/home',
  name: 'home',
  component: HomeView
}
Source: src/router/index.js:17-21
path
string
/home - Home dashboard path
name
string
home - Route name
component
Component
HomeView - Component from src/views/HomeView.vue
Usage:
this.$router.push('/home');
// or
this.$router.push({ name: 'home' });

Pre-Students Photos Route

Photo management for pre-students (applicants/pre-enrolled).
{
  path: '/estudiantes_pre_pictures',
  name: 'Estudiantes Pre',
  component: Estudiantes_Pre_FotoViews
}
Source: src/router/index.js:22-26
path
string
/estudiantes_pre_pictures - Pre-students photo management
name
string
Estudiantes Pre - Route name
component
Component
Estudiantes_Pre_FotoViews - Component from src/views/FotosViews/Estudiantes_Pre_FotoViews.vue

Pre-Students Registration Route

Individual registration for pre-students.
{
  path: '/estudiantes_pre_registro',
  name: 'Estudiantes Pre R',
  component: Registro_IndvPreEst
}
Source: src/router/index.js:27-31
path
string
/estudiantes_pre_registro - Pre-student individual registration
name
string
Estudiantes Pre R - Route name
component
Component
Registro_IndvPreEst - Component from src/views/FotosViews/Registro_IndvPreEst.vue

Students Photos Route

Photo management for regular enrolled students.
{
  path: '/estudiantes_pictures',
  name: 'Estudiantes',
  component: Estudiantes_FotoViews
}
Source: src/router/index.js:32-36
path
string
/estudiantes_pictures - Students photo management
name
string
Estudiantes - Route name
component
Component
Estudiantes_FotoViews - Component from src/views/FotosViews/Estudiantes_FotoViews.vue

Teachers Photos Route

Photo management for teachers/docentes.
{
  path: '/docentes_pictures',
  name: 'Docentes',
  component: Docentes_FotoViews
}
Source: src/router/index.js:37-41
path
string
/docentes_pictures - Teachers photo management
name
string
Docentes - Route name
component
Component
Docentes_FotoViews - Component from src/views/FotosViews/Docentes_FotoViews.vue

Teachers Registration Route

Individual registration for teachers.
{
  path: '/docentes_registro',
  name: 'DocenteR',
  component: Registro_IndvDoc
}
Source: src/router/index.js:42-46
path
string
/docentes_registro - Teacher individual registration
name
string
DocenteR - Route name
component
Component
Registro_IndvDoc - Component from src/views/FotosViews/Registro_IndvDoc.vue

Students Registration Route

Individual registration for students.
{
  path: '/estudiantes_registro',
  name: 'EstudianteR',
  component: Registro_IndvEst
}
Source: src/router/index.js:47-51
path
string
/estudiantes_registro - Student individual registration
name
string
EstudianteR - Route name
component
Component
Registro_IndvEst - Component from src/views/FotosViews/Registro_IndvEst.vue

About Route (Lazy Loaded)

About page with code splitting.
{
  path: '/about',
  name: 'about',
  component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
}
Source: src/router/index.js:52-59
path
string
/about - About page
name
string
about - Route name
component
Function
Lazy-loaded component using dynamic import. This creates a separate chunk (about.[hash].js) that is only loaded when the route is visited.

Programmatic Navigation

Using Path

// Navigate to home
this.$router.push('/home');

// Navigate to teachers photos
this.$router.push('/docentes_pictures');

// Navigate back to login
this.$router.push('/');

Using Named Routes

// Navigate to home
this.$router.push({ name: 'home' });

// Navigate to students photos
this.$router.push({ name: 'Estudiantes' });

// Navigate to login
this.$router.push({ name: 'login' });
<template>
  <router-link to="/home">Go to Home</router-link>
  <router-link :to="{ name: 'Docentes' }">Teachers</router-link>
</template>
While not implemented in the current router configuration, you can add navigation guards:
router.beforeEach((to, from, next) => {
  // Check if user is authenticated
  const isAuthenticated = store.getters.isAuthenticated;
  
  // Redirect to login if not authenticated and trying to access protected route
  if (to.name !== 'login' && !isAuthenticated) {
    next({ name: 'login' });
  } else {
    next();
  }
});

Route Organization

The routes are organized into three main categories:

Authentication

  • / - Login page

Photo Management

  • /docentes_pictures - Teachers photos
  • /estudiantes_pictures - Students photos
  • /estudiantes_pre_pictures - Pre-students photos

Individual Registration

  • /docentes_registro - Teacher registration
  • /estudiantes_registro - Student registration
  • /estudiantes_pre_registro - Pre-student registration

Other

  • /home - Dashboard
  • /about - About page (lazy loaded)

Best Practices

Use Named Routes

Prefer named routes for better maintainability:
// Good
this.$router.push({ name: 'home' });

// Acceptable
this.$router.push('/home');

Handle Navigation Errors

try {
  await this.$router.push({ name: 'home' });
} catch (error) {
  if (error.name !== 'NavigationDuplicated') {
    console.error('Navigation error:', error);
  }
}

Check Current Route

// Get current route
const currentRoute = this.$route;

console.log('Current path:', currentRoute.path);
console.log('Current name:', currentRoute.name);

// Check if on specific route
if (this.$route.name === 'home') {
  console.log('User is on home page');
}

Access Route Parameters

// Access route params
const params = this.$route.params;

// Access query parameters
const query = this.$route.query;

// Example: /user/123?tab=profile
console.log(this.$route.params.id);    // '123'
console.log(this.$route.query.tab);     // 'profile'

History Mode

The router uses HTML5 History mode (createWebHistory), which:
  • Provides clean URLs without hash (#) fragments
  • Requires server configuration to handle client-side routes
  • Falls back to hash mode if the browser doesn’t support it

Server Configuration

For production, configure your server to serve index.html for all routes: Nginx example:
location / {
  try_files $uri $uri/ /index.html;
}
Apache example (.htaccess):
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

Route Metadata

Currently, routes don’t have metadata, but you can add it:
{
  path: '/home',
  name: 'home',
  component: HomeView,
  meta: {
    requiresAuth: true,
    roles: ['sotics', 'atics', 'sa'],
    title: 'Dashboard'
  }
}
Then use it in navigation guards:
router.beforeEach((to, from, next) => {
  if (to.meta.requiresAuth) {
    // Check authentication
  }
  
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  
  next();
});

Build docs developers (and LLMs) love