Search by

innoboxrr / routes-to-json

hrauvc

A partir de las rutas del sistema, laravel crea un archivo json en la ubicación especificada en el archivo de configuración para que sean resueltas en el frontend por el paquete route-resolver

Package info

github.com/innoboxrr/routes-to-json

pkg:composer/innoboxrr/routes-to-json

Statistics

Installs: 802

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

2.1.0 2026-09-13 23:52 UTC

This package is auto-updated.

Last update: 2026-09-14 04:26:33 UTC


README

Stop hardcoding URLs in your frontend.

Your Laravel routes already have names. This package exports them to a JSON file your JavaScript can read, so the frontend resolves URLs the same way Blade does — by name, not by string.

php artisan route:json
{
    "user.profile": "users/{id}/profile",
    "invoice.show": "invoices/{invoice}"
}

Only named routes are exported: a route without a name can't be requested by name, so it is skipped.

Then resolve them in the browser with the companion package, route-resolver:

import route, { setRoutes } from 'innoboxrr-route-resolver';
import routes from './routes.json';

setRoutes(routes);

route('user.profile', { id: 42 });   // → //your-host/users/42/profile

Why it matters

Hardcoded URLs are silent breakage. You rename a route, the backend tests pass, and a button in the SPA quietly 404s in production. Naming the route on both sides makes the rename a compile-time problem instead of a support ticket.

Install

composer require innoboxrr/routes-to-json

The service provider is auto-discovered. Publishing the config is optional; its tag is config, and passing --provider keeps other packages that use the same tag from publishing their files too:

php artisan vendor:publish --provider="Innoboxrr\RoutesToJson\Providers\RoutesToJsonServiceProvider" --tag=config

Output path

By default the file is written to resources/vue/assets/json/routes.json. The config key is routes-to-json.path:

'path' => env('JSON_ROUTES_FILE', resource_path('vue/assets/json/routes.json')),
  • The directory is created if it doesn't exist.
  • A relative path is resolved against the project root (base_path()), not the current working directory.
  • An empty JSON_ROUTES_FILE= falls back to the default path.

React build

A React app doesn't live under resources/vue. Point the file to where your React code imports it from, in .env:

JSON_ROUTES_FILE=resources/react/assets/json/routes.json

and import that file from the React entry point (the exact import path depends on your Vite aliases). If the configuration is cached, run php artisan config:clear after changing the variable.

Keep it in sync

Regenerate the file whenever routes change, before building the frontend:

{
    "scripts": {
        "build": "php artisan route:json && vite build"
    }
}

Part of Innobox R&R — 52 open-source packages extracted from production work. innobox.systems

Documentación / Documentation

Documentación completa del ecosistema, en español y en inglés / Full ecosystem documentation, in Spanish and English: https://innoboxrr.github.io/docs/paquetes/routes-to-json