Skip to content

Routes Module

The routes module (lib/routes/index.js) provides a centralized location for all internal application routes. This module exports route constants and helper functions for generating dynamic routes throughout the Next.js application.

Purpose

  • Centralized route management: All internal routes are defined in one place for better maintainability
  • Type safety: Route constants prevent typos and make refactoring easier
  • Dynamic route generation: Helper functions simplify creating routes with parameters

Route Categories

Main Routes

Core application pages including home, calendar, calculator, reservations, customers, vehicles, and settings.

import { MAIN_ROUTES } from '@power-rent/lib/routes';
// Examples:
MAIN_ROUTES.HOME // '/'
MAIN_ROUTES.CALENDAR // '/calendar'
MAIN_ROUTES.RESERVATIONS // '/reservations'
MAIN_ROUTES.VEHICLES // '/vehicles'
MAIN_ROUTES.SETTINGS // '/settings'

Add Routes

Routes for creating new entities (reservations, clients, vehicles, invoices, etc.).

import { ADD_ROUTES } from '@power-rent/lib/routes';
// Examples:
ADD_ROUTES.RESERVATION // '/add/reservation'
ADD_ROUTES.CLIENT // '/add/client'
ADD_ROUTES.VEHICLE // '/add/vehicle'

View Routes

Routes for viewing specific entities by ID.

import { VIEW_ROUTES } from '@power-rent/lib/routes';
// Examples:
VIEW_ROUTES.CLIENT // '/view/client'
VIEW_ROUTES.VEHICLE // '/view/vehicle'
VIEW_ROUTES.RESERVATION // '/view/reservation'

Billion Routes

Routes specific to the Billion Rent integration and marketplace features.

import { BILLION_ROUTES } from '@power-rent/lib/routes';
// Examples:
BILLION_ROUTES.COMPANIES // '/billion/companies'
BILLION_ROUTES.VEHICLES // '/billion/vehicles'
BILLION_ROUTES.ORDER // '/billion/order'

Other Route Categories

  • MANAGE_ROUTES: Company and help management pages
  • PROFILE_ROUTES: User profile and billing pages
  • CARGOS_ROUTES: Cargos integration routes
  • AGREEMENT_ROUTES: Agreement pages
  • SELF_CHECK_IN_ROUTES: Self check-in functionality
  • SIGNATURE_REQUEST_ROUTES: Signature request pages
  • INTEGRATIONS_ROUTES: Third-party integrations (e.g., Stripe)
  • ONLINE_OFFER_ROUTES: Online offer pages
  • AUTH_ROUTES: Authentication pages (sign-in, token refresh)
  • OTHER_ROUTES: Miscellaneous pages (redirect, tracking, confirm)
  • API_ROUTES: API endpoints

Dynamic Route Generators

The module provides helper functions to generate routes with dynamic parameters:

View Routes

import { getViewRoute, getViewRouteWithQuery } from '@power-rent/lib/routes';
// Generate view route for a client
getViewRoute('CLIENT', '123') // '/view/client/123'
// Generate view route with query parameters
getViewRouteWithQuery('VEHICLE', '456', 'tab=details') // '/view/vehicle/456?tab=details'

Billion Routes

import {
getBillionCompanyRoute,
getBillionOrderRoute,
getBillionVehiclesRoute,
getBillionVehiclesStaticRoute,
} from '@power-rent/lib/routes';
getBillionCompanyRoute('company-123') // '/billion/companies/company/company-123'
getBillionOrderRoute('order-456') // '/billion/order/order-456'
getBillionVehiclesRoute('vehicle-789') // '/billion/vehicles/vehicle-789'
getBillionVehiclesStaticRoute('static-1') // '/billion/vehicles-static/static-1'

Cargos Routes

import { getCargosRoute, getCargosViewRoute } from '@power-rent/lib/routes';
getCargosRoute('CARGOS123') // '/cargos/CARGOS123'
getCargosViewRoute('view-456') // '/cargos/view/view-456'

Authentication Routes

import { getSignInRoute, getTokenRefreshRoute } from '@power-rent/lib/routes';
// Sign-in with redirect
getSignInRoute('/dashboard') // '/sign-in?path=%2Fdashboard'
// Token refresh with return URL
getTokenRefreshRoute('/profile') // '/token-refresh?returnUrl=%2Fprofile'

Other Dynamic Routes

import {
getConfirmRoute,
getConfirmApiRoute,
getSelfCheckInRoute,
getSignatureRequestRoute,
getOnlineOfferRoute,
getSettingsRoute,
getAddInvoiceRoute,
getManageCompanyRoute,
} from '@power-rent/lib/routes';
getConfirmRoute('email') // '/confirm/email'
getConfirmApiRoute('email') // '/api/confirm/email'
getSelfCheckInRoute('request-123') // '/self-check-in/request-123'
getSignatureRequestRoute('request-456') // '/signature-request/request-456'
getOnlineOfferRoute('calc-789') // '/online-offer/calc-789'
getSettingsRoute('billing') // '/settings?tab=billing'
getAddInvoiceRoute('INV-001') // '/add/invoice?number=INV-001'
getManageCompanyRoute('company-123') // '/manage/company/company-123'

Usage Examples

import { useRouter } from 'next/router';
import { MAIN_ROUTES, getViewRoute } from '@power-rent/lib/routes';
function MyComponent() {
const router = useRouter();
const handleViewClient = (clientId) => {
router.push(getViewRoute('CLIENT', clientId));
};
const handleGoToSettings = () => {
router.push(MAIN_ROUTES.SETTINGS);
};
return (
<button onClick={() => handleViewClient('123')}>
View Client
</button>
);
}
import Link from 'next/link';
import { MAIN_ROUTES, ADD_ROUTES } from '@power-rent/lib/routes';
function Navigation() {
return (
<nav>
<Link href={MAIN_ROUTES.HOME}>Home</Link>
<Link href={MAIN_ROUTES.CALENDAR}>Calendar</Link>
<Link href={ADD_ROUTES.RESERVATION}>New Reservation</Link>
</nav>
);
}

Redirects

import { redirect } from 'next/navigation';
import { AUTH_ROUTES, getSignInRoute } from '@power-rent/lib/routes';
function ProtectedPage() {
if (!isAuthenticated) {
redirect(getSignInRoute('/protected-page'));
}
// ...
}

Best Practices

  1. Always use route constants: Never hardcode route strings. Use the exported constants instead.
  2. Use helper functions for dynamic routes: Use the provided generator functions rather than manually concatenating strings.
  3. Import only what you need: Import specific route categories or functions to keep bundle size small.
  4. Type safety: The module uses Flow types for better type checking and IDE support.

Maintenance

When adding new routes:

  1. Add the route constant to the appropriate category object
  2. If the route requires dynamic parameters, add a helper function following the existing naming pattern (get*Route)
  3. Update this documentation if the route category or pattern changes significantly