Skip to content

Casa-Parks/Consume-Routes

Repository files navigation

Build Status Total Downloads Latest Stable Version License

Introduction

Consume Routes is a simple JavaScript consumer for routing (built specifically for the Laravel package Casa-Parks/Extract-Routes).

License

Extract Routes is open-sourced software licensed under the MIT license

Installation

To get started with Consume Routes, use NPM to add the package to your project's dependencies:

npm install --save capa-consume-routes

Configuration

You're going to want to generate a route collection JSON object (in the same format as tests/stubs/routes.json), you can do this automatically in Laravel via the Casa-Parks/Extract-Routes package.

Basic Usage

After providing the routes to a global object (such as window.routes), usage is as simple as:

import Router from 'capa-consume-routes';

window.router = new Router(window.routes);

Then you can use it as expected:

router.route('get::home');

router.route('get::auth.sign-in.facebook');

router.route('debugbar.clockwork', { id: 'abc' });

router.route('debugbar.clockwork', ['abc']);

router.action('App\\Http\\Controllers\\SettingsController@show');

// etc...

The two provided methods are:

/**
 * Route to a named route.
 *
 * @param {String} name
 * @param {Object|Array} parameters
 *
 * @return {String}
 */
route(name, parameters = {})

/**
 * Route to an action.
 *
 * @param {String} action
 * @param {Object|Array} parameters
 *
 * @return {String}
 */
action(action, parameters = {})