Skip to content

Commit

Permalink
Merge pull request #299 from tightenco/jbk/document-js-package
Browse files Browse the repository at this point in the history
Add documentation for using Ziggy via NPM
  • Loading branch information
bakerkretzmar authored Jun 12, 2020
2 parents 13e4740 + bf41c9f commit cc349f5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ Ziggy supports all versions of Laravel from `5.4` to `7.x`.
1. If using Laravel 5.4, add `Tightenco\Ziggy\ZiggyServiceProvider::class` to the `providers` array in your `config/app.php`.
1. Include our Blade directive (`@routes`) somewhere in your template before your main application JavaScript is loaded—likely in the header somewhere.

Ziggy is also available as an NPM package, `ziggy-js`, that exposes the `route()` function for use in frontend apps that are not using Blade or Composer. You can install the NPM package with `npm install ziggy-js` or load it from a CDN:

```html
<!-- Load the Ziggy routes object first -->
<script defer src="https://unpkg.com/[email protected]/dist/js/route.min.js"></script>
```

Note that you still have to generate your routes file with `php artisan ziggy:generate` and make it available to your frontend app.

## Usage

This package uses the `@routes` directive to inject a JavaScript object containing all of your application's routes, keyed by their names. This collection is available at `Ziggy.namedRoutes`.
Expand Down

0 comments on commit cc349f5

Please sign in to comment.