# routes-laravel-js

> ## Table of Contents - [Description](#description) - [Installing](#installing) - [Example](#example)

Latest version **1.0.0** (published 2022-01-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install routes-laravel-js
pnpm add routes-laravel-js
yarn add routes-laravel-js
bun add routes-laravel-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-01-23 |
| First published | 2022-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Thiago Melo |
| Maintainers | thiagomeloo |

## Links

- npm: https://www.npmjs.com/package/routes-laravel-js
- npm.io page: https://npm.io/package/routes-laravel-js

## Recent versions

- 1.0.0 (latest) — 2022-01-23

## README

# routes-laravel-js

## Table of Contents
  - [Description](#description)
  - [Installing](#installing)
  - [Example](#example)

## Description
  This package add routes laravel in views react.

## Installing

Using npm:

```bash
$ npm install routes-laravel-js
```

Prepare project laravel:

- make middleware
  ```php
  class RoutesLaravelJsMiddleware
  {
      public function handle(Request $request, Closure $next)
      {
          $routes = collect();

          foreach (Route::getRoutes()->getIterator() as $route) {
              $routes->push((object)[
                  'name' => $route->getName(),
                  'actionName' => $route->getActionName(),
                  'uri' => $route->uri,
                  'methods' => $route->methods,
                  'middleware' => $route->middleware(),
              ]);
          }
          $request->headers->set('X-Routes', $routes->toJson());

          return $next($request);
      }
  }

  ```

- add in middleware to kernel.php
  ```php
  protected $middleware = [
      RoutesLaravelJsMiddleware::class,
  ];
  ```

## Example

- add in app.blade.php
  ```php
    <meta name="x-routes" content="{{ app('request')->header('X-Routes', 'default_header_value') }}" />
  ```
- usage in component
  ```js
  import { Routes } from 'routes-laravel-js';

  export default function HomePage(props) {
      let routes = Routes.init();
      return (
          <div>
              <h1>Home Page</h1>
              <a href={routes.getUri('home')}>Home</a>
          </div>
      );
  }
  ```

---
_Source: https://npm.io/package/routes-laravel-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
