innoboxrr/routes-to-json

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
2,432
Install
composer require innoboxrr/routes-to-json
Latest Version:2.1.0
PHP:^8.3
License:MIT
Last Updated:Sep 14, 2026
Links: GitHub  ·  Packagist
Maintainer: hrauvc

Routes to JSON

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

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

637,827,751 9,703
laravel/framework

The Laravel Framework.

589,172,971 34,950
laravel/tinker

Powerful REPL for the Laravel framework.

498,216,183 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

413,412,504 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

394,964,158 4,660

Version History

Version Released PHP Laravel License
2.1.0 ^8.3 ^13.0 MIT
2.0.0 ^8.3 ^13.0 MIT
1.0.7 MIT
1.0.6 MIT
1.0.5 MIT