-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from tightenco/jbk/document-js-package
Add documentation for using Ziggy via NPM
- Loading branch information
Showing
1 changed file
with
9 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`. | ||
|