xactsystems/js-routing-bundle

用于Symfony 4+的webpack路由包。源自FOS JSRoutingBundle。查看3.4分支以获取Symfony 3.4版本。

安装: 911

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v5.0.0 2024-09-25 15:49 UTC

This package is auto-updated.

Last update: 2024-09-25 15:52:13 UTC


README

此包允许您公开您的Symfony路由并在webpack管理的JavaScript代码中使用它们。它允许您轻松地将FOSJsRoutingBundle的功能集成到webpack模块中。

文档

1) 将JSRoutingBundle添加到您的项目中

composer require xactsystems/js-routing-bundle

对于Symfony 3.4使用

composer require xactsystems/js-routing-bundle:^3.4

2) 在您的基Twig模板中包含路由模板

// templates/base.html.twig

{{ include("@XactJSRouting/js-routing.html.twig") }}

3) 在App.js中包含JS模块

// assets/js/App.js

// Import the JS routing scripts
import '../../vendor/xactsystems/js-routing-bundle/assets/js-routing.js';

js-routing.js文件的实际路径可能不会与显示的完全相同,您可能需要根据您的项目调整此路径。

4) 使用路由类,方法与FOS包完全相同

// Get the URL of your routes
let url1 = Routing.generate('home');
let url2 = Routing.generate('some-other-route', {id: myLocalId, state: myLocalState});

5) 对于Symfony 3.4,如果您不使用Flex和ENV,您可能需要添加以下内容

// app/AppKernel.php

    public function registerBundles()
    {
        // You many need to do this to get the render(controller()) Twig method working for XactJSRoutingBundle
        $_ENV["APP_ENV"] = $this->getEnvironment();

并且对于Symfony Serializer组件

// app/config/config.yml

framework:
    ...
    # If you haven't already enabled the Symfony Serializer
    serializer: { enabled: true }

致谢

  • Ian Foulds是这个包的创建者。
  • William DURAND是FOS包的作者。
  • Julien MUETTON(Carpe Hora)提供灵感。

许可证

此包在MIT许可证下发布。请参阅包中的完整许可证。

LICENSE