AngularJS symfony2 应用程序中的路由

AngularJS route in symfony2 app

我在我的 symfony 应用程序中成功安装了 angularJS。

当调用“/”时,我的 symfony 控制器匹配特定模板上的路由。这是唯一一次调用 symfony 控制器操作。

应用程序的其余部分都通过 angularJS - 路由。

所有 angularjs 个特定视图位于

web/*

当我单击 link,即“/friends”时,会加载正确的 html 文件。

url是:

http://example.com/friends

当我单击另一个 link,即“/trash”时,也会加载正确的 html 文件。

url是:

http://example.com/trash

但是当我重新加载页面时,symfony 试图找到一个路由“/trash”并遇到错误 404。

有什么办法可以解决这个问题吗?

谢谢和问候!

那是因为您正在发送一个 http 请求,而 symfony2 的内核使用路由进行处理,如果您看到 The Symfony Application Flow you can better understand. How to solve this?, I personally use ui-router (the routing framework for AngularJs) with this, your url will be like this: http://example.com/#trash, (with # ), you can see this tutorial 了解更多详细信息。如果您需要更多帮助,请将代码放在 github 上,我的用户帐户是 ricky6982。