我目前正在进行一个大型重构项目,我的团队正在用更现代的方法替换应用程序中的旧功能。
我们正在转向单页面应用程序方法,但在此之前,我们正在用 AngularJS 功能替换单个独立网页。
我们的后端是 ASP.NET MVC 应用程序,我不得不使用我目前拥有的任何东西;因此 URL 等需要保持给定格式:
http://example.com/controller/action/id
如何在不使用 AngularJS 单页应用程序最常使用的所谓散列式 URL 的情况下读取我的 AngularJS Controller 中的 URL 部分?
例如;
我转到 /user/edit/1
并需要以某种方式在我的 AngularJS Controller 中获取“1
”的 ID。
如有任何帮助,我们将不胜感激!
最佳答案
$location 服务可以在这里帮助您。根据文档 https://code.angularjs.org/1.2.15/docs/guide/ $位置
$location service provides getter methods for read-only parts of the URL (absUrl, protocol, host, port) and getter / setter methods for url, path, search, hash:
关于javascript - AngularJS - 如何在非单页应用程序中从干净的 URL 读取 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26400894/