PHPackages                             vaened/laroute - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vaened/laroute

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vaened/laroute
==============

An enhanced Laravel extension to export named routes to JavaScript, allowing you to use route names instead of URLs. Supports route grouping for modular applications.

v2.0.0(4mo ago)4127.1k↓14.4%1MITPHPPHP ^8.2CI passing

Since Aug 22Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/vaened/laroute)[ Packagist](https://packagist.org/packages/vaened/laroute)[ RSS](/packages/vaened-laroute/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (7)Used By (0)

Laroute
=======

[](#laroute)

[![Build Status](https://github.com/vaened/laroute/actions/workflows/tests.yml/badge.svg)](https://github.com/vaened/laroute/actions?query=workflow:Tests) [![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license)

`vaened\laroute` is a PHP library inspired by [aaronlord/laroute](https://github.com/aaronlord/laroute), designed to help Laravel developers manage their application’s routes in `JavaScript` without the need to hardcode `URLs`. This library goes a step further by introducing modular routing, allowing you to separate routes based on URL patterns into different modules. Each module generates its own routes file, making it easier to manage and scale your application’s routing structure.

[ ![routes-example](.github/images/routes-example.jpg)](#)Installation
------------

[](#installation)

Laroute requires PHP 8.2. To get the latest version, simply require the project using Composer:

```
composer require vaened/laroute
```

Publish the configuration file.

```
php artisan vendor:publish --tag='laroute'
```

Now, generate the routes based on your configuration and export the JavaScript service.

```
php artisan laroute:generate
```

Usage
-----

[](#usage)

The library includes the necessary `javascript` service to interpret the exported routes, along with its corresponding `d.ts` type definitions for `typescript`.

> The location of the service is configured in the library option within the configuration file.

### Javascript / Typescript

[](#javascript--typescript)

Once the service is exported to the location defined in the configuration file, you can easily create a new file and export the service creation by passing the file containing the routes as a parameter.

```
import {RouteService} from "./laroute";
import routes from "./api-routes.json";

const apiRouteService = new RouteService({routes});
```

With this, you’re ready to start.

```
const response = await fetch(apiRouteService.generateFullURL('store.products.lists'))
const data = response.json();
console.log(data)
```

Additionally, you can export the routes as a TypeScript file to enable route autocompletion in your editor. To achieve this, simply modify the `output` option in the configuration file.

[ ![routes-example](.github/images/autocomplete-route-name.gif) ](#)### Service

[](#service)

The route service provides three key methods to interact with the generated routes:

- **generateFullURL(name, ?params)**: Generates a full URL, including any query string parameters.

```
apiRouteService.generateFullURL('admin.products.create', {
    id: '80768395-4208-4fd7-ac60-c429717014ab',
    name: 'Notebook'
})
```

> Returns `{host}/api/admin/products/80768395-4208-4fd7-ac60-c429717014ab?name=Notebook`

- **createURLWithoutQuery(name, ?params)**:Generates a full URL without any query string.

```
apiRouteService.createURLWithoutQuery('admin.products.update', {
    id: '80768395-4208-4fd7-ac60-c429717014ab',
    name: 'Notebook'
})
```

> Returns `{host}/api/admin/products/80768395-4208-4fd7-ac60-c429717014ab`

- **has(name)**: Checks if a specific route is defined within the service.

```
apiRouteService.has('admin.products.list')
```

> Returns `true` if the route exists, `false` otherwise.

### Best Practices

[](#best-practices)

To efficiently manage API calls, it’s advisable to create a dedicated file. You might name it `Router.{ts, js}`. In this file, you can utilize `fetch` or a library like `axios` to streamline your API interactions. An example of what you might export could look like this:

```
import createRouteService, {Parameters} from "./laroute";
import axios, {AxiosRequestConfig, AxiosResponse} from "axios";
import api from "./api.json";

const apiRouteService = createRouteService(api);

export const Router = {
    get(routeName: string, params: Parameters = {}, config: AxiosRequestConfig = {}) {
        return axios.get(apiRouteService.cleanURI(routeName, params), {params, ...config});
    },

    post(routeName: string, params: Parameters = {}, config: AxiosRequestConfig = {}) {
        return axios.post(apiRouteService.cleanURI(routeName, params), params, config);
    },

    patch(routeName: string, params: Parameters = {}, config: AxiosRequestConfig = {}) {
        return axios.patch(apiRouteService.cleanURI(routeName, params), params, config);
    },
    // ...
};
```

Configuration
-------------

[](#configuration)

The default configuration should be sufficient for most projects, allowing you to simply export the routes and start working without any additional setup.

> For customization options, refer to the comments in the configuration file [laroute.php](./config/laroute.php).

### Advanced

[](#advanced)

For larger projects, where different clients consume the API, you can configure the route export in a modular way. This allows you to create as many modules as needed, each corresponding to different URL segments.

For example, you could have a module for `/api/store` and another for `/api/admin`, which would generate two separate route files.

```
'modules' => [
  [
    'match'    => '/api/store',
    'name'     => 'store',
    'rootUrl'  => 'https://store.aplication.com',
    'absolute' => true,
    'path'     => 'resources/routes',
  ],
  [
    'match'    => '/api/admin',
    'name'     => 'admin',
    'rootUrl'  => 'https://admin.aplication.com',
    'absolute' => true,
    'path'     => 'resources/routes',
  ],
]
```

Features
--------

[](#features)

- **Modular Routing**: Define and separate routes by modules based on URL patterns (e.g., /api, /admin, /user), with each module generating a separate JSON file.
- **Seamless Integration with Laravel**: Automatically generate JavaScript routes from your Laravel routes, ensuring consistency across your application.
- **TypeScript Support**: Includes a TypeScript-compatible JavaScript file, allowing you to use strongly-typed route definitions in your front-end code.
- **Customizable URLs**: Generate absolute or relative URLs with customizable prefixes and root URLs, giving you full control over how URLs are constructed.
- **Flexible Configuration**: Easily configure modules and route matching criteria to fit the needs of your project, whether it’s a monolithic application or a modular one.

License
-------

[](#license)

This library is licensed under the MIT License. For more information, please see the [`license`](./license) file.

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance75

Regular maintenance activity

Popularity37

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Recently: every ~124 days

Total

6

Last Release

134d ago

Major Versions

v0.1 → v1.02024-08-23

v1.2.1 → v2.0.02026-01-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebfa2dc9bcd9f9f7cea1f5473811d3c3904f60716e5605ab0d7208a9a6b81f09?d=identicon)[vaened](/maintainers/vaened)

---

Top Contributors

[![vaened](https://avatars.githubusercontent.com/u/15077850?v=4)](https://github.com/vaened "vaened (54 commits)")

---

Tags

laravel-packagelaravel-rest-apilaravel-routesroutingroutesroutinglaravel-library

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vaened-laroute/health.svg)

```
[![Health](https://phpackages.com/badges/vaened-laroute/health.svg)](https://phpackages.com/packages/vaened-laroute)
```

###  Alternatives

[tightenco/ziggy

Use your Laravel named routes in JavaScript.

4.3k41.6M267](/packages/tightenco-ziggy)[lord/laroute

Access Laravels URL/Route helper functions, from JavaScript.

8022.0M8](/packages/lord-laroute)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)[te7a-houdini/laroute

Access Laravels URL/Route helper functions, from JavaScript.

33512.1k](/packages/te7a-houdini-laroute)[dragon-code/laravel-route-names

Automatic generation of route names

259.2k1](/packages/dragon-code-laravel-route-names)[devaly/wordpress-routes

Manage rewrites and routes in WordPress with this dead-simple plugin

101.3k](/packages/devaly-wordpress-routes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
