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

ActiveLibrary

inventas/momentum-trail
=======================

Fully typed frontend route helper for Laravel apps

01↓100%PHPCI passing

Since Mar 19Pushed 1mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Momentum Trail (Inventas Fork)
==============================

[](#momentum-trail-inventas-fork)

Important

This is a fork of [lepikhinb/momentum-trail](https://github.com/lepikhinb/momentum-trail) maintained by [Inventas](https://github.com/Inventas). We've created this fork to provide support for Laravel 13 as the original repository appears to be inactive.

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 inventas/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

21

—

LowBetter than 19% of packages

Maintenance59

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 57.1% 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.

### Community

Maintainers

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

---

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)")[![LambdaDigamma](https://avatars.githubusercontent.com/u/19361610?v=4)](https://github.com/LambdaDigamma "LambdaDigamma (3 commits)")[![ycs77](https://avatars.githubusercontent.com/u/38133356?v=4)](https://github.com/ycs77 "ycs77 (2 commits)")[![studnitz](https://avatars.githubusercontent.com/u/9549394?v=4)](https://github.com/studnitz "studnitz (1 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)")

### Embed Badge

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

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

PHPackages © 2026

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