PHPackages                             based/momentum-trail - 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. based/momentum-trail

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

based/momentum-trail
====================

Fully typed frontend route helper for Laravel apps

v0.4.0(1y ago)80389.6k—6.1%12[2 PRs](https://github.com/lepikhinb/momentum-trail/pulls)MITPHPPHP ^8.1CI passing

Since Dec 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/lepikhinb/momentum-trail)[ Packagist](https://packagist.org/packages/based/momentum-trail)[ GitHub Sponsors](https://github.com/lepikhinb)[ RSS](/packages/based-momentum-trail/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (7)Used By (0)

Momentum Trail
==============

[](#momentum-trail)

Momentum Trail is a Laravel package that provides a TypeScript `route()` helper function that works like Laravel's, making it easy to use your Laravel named routes in TypeScript with auto-completion and type-safety.

The package is built on top of [Ziggy](https://github.com/tighten/ziggy).

- [**Installation**](#installation)
    - [**Laravel**](#laravel)
    - [**Frontend**](#frontend)
- [**Usage**](#usage)
- [**Auto-generation**](#auto-generation)
- [**Advanced Inertia**](#advanced-inertia)
- [**Momentum**](#momentum)

Installation
------------

[](#installation)

### Laravel

[](#laravel)

Install the package using `composer`.

```
composer require based/momentum-trail
```

You can publish the config file with:

```
php artisan vendor:publish --tag=trail-config
```

This is the contents of the published config file:

```
return [
    'output' => [
        'routes' => resource_path('scripts/routes/routes.json'),
        'typescript' => resource_path('scripts/types/routes.d.ts'),
    ],
];
```

Set the paths according to your directory structure. You can set the `routes` path to `null` in case you plan to use the `Blade` directive instead of importing JSON.

### Frontend

[](#frontend)

Install the [frontend package](https://github.com/lepikhinb/momentum-trail-helper).

```
npm i momentum-trail
# or
yarn add momentum-trail
```

Usage
-----

[](#usage)

Run the following command to generate TypeScript declarations and make your routes available on the frontend.

```
php artisan trail:generate
```

Register your routes on the frontend. You can either import the generated JSON definition and pass it to the `defineRoutes` method within the entry point (`app.ts`) or use the `@trail` Blade directive to register routes in the `window` object and make them available globally.

```
import { defineRoutes } from "momentum-trail"
import routes from "./routes.json"

defineRoutes(routes)
```

### Vue 3

[](#vue-3)

Alternatively, you can register routes using a Vue 3 plugin.

```
import { trail } from "momentum-trail"
import routes from "./routes.json"

createInertiaApp({
  setup({ el, app, props, plugin }) {
    createApp({ render: () => h(app, props) })
      .use(trail, { routes })
  }
})
```

#### Server-side rendering

[](#server-side-rendering)

The SSR engine *doesn't know* the current URL you are requesting.

To make the method `current` work correctly on the initial page load, you must pass the initial URL to the options list.

```
createServer((page: Page) =>
  createInertiaApp({
    setup({ App, props, plugin }) {
      return createSSRApp({ render: () => h(App, props) })
        .use(trail, {
          routes,
          url: props.initialPage.url
        })
    },
  })
)
```

### Blade

[](#blade)

Optionally, add the `@trail` Blade directive to your main layout (before your application's JavaScript).

> By default, the output of the @trail Blade directive includes a list of all your application's routes and their parameters. This route list is included in the HTML of the page and can be viewed by end users.

```

  @trail

```

Import the helper in your `.vue` files and enjoy perfect autocompletion and type-safety for both `route` and `current` methods.

```

import { route, current } from "momentum-trail"

const submit = () => form.put(route("profile.settings.update"))

    Users

```

The `route` helper function works like Laravel's — you can pass it the name of one of your routes, and the parameters you want to pass to the route, and it will return a URL.

```
// Generate a URL
route("jobs.index")
route("jobs.show", 1)
route("jobs.show", [1])
route("jobs.show", { job: 1 })

// Check the current route
current("jobs.*")
current("jobs.show")
current("jobs.show", 1)
```

For the complete documentation please refer to [Ziggy](https://github.com/tighten/ziggy#usage).

### Auto-generation

[](#auto-generation)

The package works best with [vite-plugin-watch](https://github.com/lepikhinb/vite-plugin-watch) plugin. You can set up the watcher to run the command on every file change.

```
import { defineConfig } from "vite"
import { watch } from "vite-plugin-watch"

export default defineConfig({
  plugins: [
    watch({
      pattern: "routes/*.php",
      command: "php artisan trail:generate",
    }),
  ],
})
```

Advanced Inertia
----------------

[](#advanced-inertia)

[![](https://camo.githubusercontent.com/6d303aa5ddd234c4e468400424ebf0c4267e6c5dba44e51f96dec88dc6e8b29f/68747470733a2f2f616476616e6365642d696e65727469612e636f6d2f6f672e706e67)](https://advanced-inertia.com)

Take your Inertia.js skills to the next level with my book [Advanced Inertia](https://advanced-inertia.com/). Learn advanced concepts and make apps with Laravel and Inertia.js a breeze to build and maintain.

Momentum
--------

[](#momentum)

Momentum is a set of packages designed to improve your experience building Inertia-powered apps.

- [Modal](https://github.com/lepikhinb/momentum-modal) — Build dynamic modal dialogs for Inertia apps
- [Preflight](https://github.com/lepikhinb/momentum-preflight) — Realtime backend-driven validation for Inertia apps
- [Paginator](https://github.com/lepikhinb/momentum-paginator) — Headless wrapper around Laravel Pagination
- [Trail](https://github.com/lepikhinb/momentum-trail) — Frontend package to use Laravel routes with Inertia
- [Lock](https://github.com/lepikhinb/momentum-lock) — Frontend package to use Laravel permissions with Inertia
- [Layout](https://github.com/lepikhinb/momentum-layout) — Persistent layouts for Vue 3 apps
- [Vite Plugin Watch](https://github.com/lepikhinb/vite-plugin-watch) — Vite plugin to run shell commands on file changes

Credits
-------

[](#credits)

- [Boris Lepikhin](https://twitter.com/lepikhinb)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance45

Moderate activity, may be stable

Popularity50

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% 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 ~164 days

Recently: every ~205 days

Total

6

Last Release

428d ago

PHP version history (2 changes)v0.1.0PHP ^8.0

v0.4.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![lepikhinb](https://avatars.githubusercontent.com/u/17538801?v=4)](https://github.com/lepikhinb "lepikhinb (20 commits)")[![ccharz](https://avatars.githubusercontent.com/u/2725238?v=4)](https://github.com/ccharz "ccharz (4 commits)")[![sweptsquash](https://avatars.githubusercontent.com/u/9886472?v=4)](https://github.com/sweptsquash "sweptsquash (3 commits)")[![ycs77](https://avatars.githubusercontent.com/u/38133356?v=4)](https://github.com/ycs77 "ycs77 (2 commits)")[![michaeldyrynda](https://avatars.githubusercontent.com/u/558441?v=4)](https://github.com/michaeldyrynda "michaeldyrynda (1 commits)")[![daronspence](https://avatars.githubusercontent.com/u/4062087?v=4)](https://github.com/daronspence "daronspence (1 commits)")[![studnitz](https://avatars.githubusercontent.com/u/9549394?v=4)](https://github.com/studnitz "studnitz (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/based-momentum-trail/health.svg)

```
[![Health](https://phpackages.com/badges/based-momentum-trail/health.svg)](https://phpackages.com/packages/based-momentum-trail)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)[illuminate/cookie

The Illuminate Cookie package.

224.3M122](/packages/illuminate-cookie)

PHPackages © 2026

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