Use your Masonite named routes in Javascript
Project description
Masonite JS Routes
Introduction
Use your Masonite named routes in Javascript !
This package creates a helper that you can include in your views. It will export a JavaScript object of your application's named routes, keyed by their names (aliases).
You can combine it with ziggy-js library as to get a global route()
helper function which you can use to access your routes in your JavaScript.
Features
- Add your package main features here
- and here
Official Masonite Documentation
New to Masonite ? Please first read the Official Documentation. Masonite strives to have extremely comprehensive documentation 😃. It would be wise to go through the tutorials there. If you find any discrepencies or anything that doesn't make sense, be sure to comment directly on the documentation to start a discussion!
Also be sure to join the Slack channel!
Installation
pip install masonite-js-routes
Configuration
Add JSRoutesProvider to your project in config/providers.py
:
# config/providers.py
# ...
from masonite.js_routes import JSRoutesProvider
# ...
PROVIDERS = [
# ...
# Third Party Providers
JSRoutesProvider,
# ...
]
You can skip this step if you don't want to filters routes included by the helper. Else you must publish the config file by running the command:
python craft js_routes:install
Then you should have a new js_routes.py
config file in config/
.
python craft js_routes:install
Usage
In your views, just add this helper where you want to get Ziggy
routes as a Javascript object:
{{ js_routes() }}
Basic filtering
Only the routes matching a list of name patterns will be included:
FILTERS = {
"only": ["welcome.*"],
}
Only the routes which does not match a list of name patterns will be included:
FILTERS = {
"except": ["admin.*"],
}
Note: You have to choose one or the other. Setting both only
and except
will disable filtering altogether and simply return the default list of routes.
Filtering using Groups
Only the routes matching a group or a list of groups will be included if groups are passed to the helpers
FILTERS = {
"groups": {
"app": ["app.*"],
"api": ["api.*"],
}
}
and in your view :
{{ js_routes('app') }}
or a list of group names
{{ js_routes(['app', 'api']) }}
Note: Passing group names to the routes
helper will always take precedence over your other only or except settings.
Content Security Policy
A Content Security Policy may block unsafe inline scripts which Ziggy uses to pass the routes to JavaScript. By adding a nonce to your CSP you can allow certain inlined scripts. To add this nonce to Ziggy you can pass it as the second argument to the helper:
{{ routes(false, '[YOUR_NONCE]') }}
Contributing
Please read the Contributing Documentation here.
License
Masonite JS Routes is open-sourced software licensed under the MIT license.
Disclaimer: this package is based on the Laravel package Ziggy.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for masonite_js_routes-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a02d31e23340c1a09cc6a139894878e1acb237dd95afdcc12e3b5bb7413bf984 |
|
MD5 | 888d3058016c2fab6e9286f4d8c0821d |
|
BLAKE2b-256 | 179adfbe4d7534a793aa958aaa1fbae8ef7a1de856bb41c1748dae1a01e3cecc |