0

我正在开发 symfony 项目(版本 3.4) 我想从 javacsript 文件访问路由。我在 symfony 文档中看到我可以使用 FOSJsRoutingBundle。我已按照文档进行安装和配置,但是当我尝试访问我的网站时,出现此错误:Uncaught SyntaxError: Unexpected identifier。这与添加到我的 js 文件中的这一行有关:

从'../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js'导入路由;

这是我在 dev.log 文件中得到的:

[2018-11-30 22:50:53] request.INFO: Matched route "ens_category_page". {"route":"ens_category_page","route_parameters":{"_controller":"JobeetBundle\\Controller\\CategoryController::indexAction","_route":"ens_category_page"},"request_uri":"http://localhost:8888/jobeet/web/app_dev.php/categories","method":"GET"} []

[2018-11-30 22:50:53] security.INFO:使用匿名令牌填充 TokenStorage。[] [] [2018-11-30 22:50:54] 学说.DEBUG: SELECT t0.id AS id_1, t0.name AS name_2 FROM category t0 [] [] [2018-11-30 22:50:55 ] request.INFO:匹配路由“fos_js_routing_js”。{"route":"fos_js_routing_js","route_parameters":{"_controller":"fos_js_routing.controller:indexAction","_format":"js","_route":"fos_js_routing_js"},"request_uri":" http: //localhost:8888/jobeet/web/app_dev.php/js/routing?callback=fos.Router.setData ","method":"GET"} [] [2018-11-30 22:50:56] 请求.INFO:匹配的路由“_wdt”。{"route":"_wdt","route_parameters":{"_controller"","方法":"GET"} []

提前感谢您的回复。在此处输入图像描述

4

1 回答 1

0

什么是意外标识符?您是否复制了完整的错误消息?

除了在您的 js 文件中导入路由,您可以尝试在您的布局中加载 fos,如此处所述

<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
于 2018-12-01T00:16:52.397 回答