rpsimao/laravel-js-routing
Composer 安装命令:
composer require rpsimao/laravel-js-routing
包简介
Laravel 5 package to access Routing from Javascript
README 文档
README
This package allows you to access Laravel's routing from your Javascript.
The main feature is the possibility to use it easily in local and production environment.
In local environment, the JS routes are re-written each request. In production environment, the JS routes are dumped in a static file for better performance.
Installation
Add this line to your composer.json and run composer update
"delormejonathan/laravel-js-routing": "~2.0"
Only for (Laravel <5.5) Add the provider to app.php to the providers section
DelormeJonathan\LaravelJsRouting\LaravelJsRoutingServiceProvider::class,
Only for (Laravel <5.5) Add the facade to app.php to the aliases section
'JSRouter' => DelormeJonathan\LaravelJsRouting\Facades\JSRouter::class,
Publish assets to public folder
php artisan vendor:publish --tag=public --force
Usage
Call the JSRouter plugin in your application template :
<script type="text/javascript" src="{{ asset('packages/rpsimao/laravel-js-routing/jsrouter.js') }}"></script>
And import routes file dynamically in local and statically in production :
@if (App::environment() == 'production') <script type="text/javascript" src="/js/routes.js"></script> @else <script type="text/javascript">{!! JSRouter::generate() !!}</script> @endif
Now, you can use it in JavaScript :
JSRouter.action('UsersController@edit', { id : 5 }); // For routes without a name JSRouter.route('mycustomroutename'); // For routes with a name
Don't forget to export routes in production. You can add a custom path right after the 'dump' word. Default path is : public/js/routes.js
php artisan laravel-js-routing:dump
php artisan laravel-js-routing:dump public/mycustompath/mycustomfile.js
Configuration
You can change the default path with the configuration file. You have to publish the config file :
php artisan config:publish delormejonathan/laravel-js-routing
Then modify it in app/config/packages.
Common issues
Browser console report "No routes detected"
Make sure you have at least one route with a name or a controller in your routes.php.
I added a route to Laravel and the JSRouter doesn't see it
If you are in production environment, remember to export your routes with php artisan laravel-js-routing:dump when you change your routes.php
If you are in local environment, remember that your route needs to point to a controller. It can have a name (optional). This package doesn't work with Closure routes.
Contribution & improvements
The plugin is pretty basic currently. He needs a better parsing engine to manage optional parameters.
Issues or features
Feel free to open an issue if you encounter a problem or contact me directly.
Credits
- FOSJsRoutingBundle for the inspiration.
License
This project is licensed under the MIT license.
rpsimao/laravel-js-routing 适用场景与选型建议
rpsimao/laravel-js-routing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 55 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 05 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「routing」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rpsimao/laravel-js-routing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rpsimao/laravel-js-routing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rpsimao/laravel-js-routing 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Write down your routing mapping at one place
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
A router designed for web requests for the Monolith framework
Dynamic database routing for Symfony2.
统计信息
- 总下载量: 55
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-02