当前位置: 动力学知识库 > 问答 > 编程问答 >

AngularJS route in symfony2 app

问题描述:

I successfully installed angularJS in my symfony app.

When "/" is called my symfony controller matches the route on a specific template. This is the only time a symfony controller action is called.

The entire rest of the application is routed through angularJS - route.

All angularjs specific views are located in

web/*

When i click a link i.e. "/friends", the proper html-file is loaded.

The url is:

http://example.com/friends

When i click an other link i.e. "/trash", the proper html-file is loaded too.

The url is:

http://example.com/trash

But when i reload the page, symfony tries to find a route "/trash" and throughs an error 404.

Is there any way to get around this?

Thanks and Greetings!

网友答案:

That's because you are sending a http request, and symfony2's kernel it processes with Routing, if you see 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 for more details. If you need more help put the code on github, my user account is ricky6982.

分享给朋友:
您可能感兴趣的文章:
随机阅读: