简体   繁体   English

无斜杠的AngularJS路由

[英]AngularJS route without slash

in AngularJS can I set up a style route like this: 我可以在AngularJS中设置这样的样式路线:

http://www.mydomain.com/title-and-more-irrelevant-text-123456-category.html

where '123546' is an indentifier ? 其中“ 123546”是标识符?

with: 与:

$locationProvider.html5Mode(true);

I must make this because I need keep the old URLs 我必须这样做,因为我需要保留旧的网址

If this is the entire path, then I guess it will be hard because it is too generic. 如果这是完整的路径,那么我想这会很困难,因为它太通用了。

If however you can live with paths in the form /prefix/title-and-stuff-123456-foo.html (ie the entire URL would look like http://mysrv.com/ctx/#/prefix/title-and-stuff-123.html ), read on. 但是,如果您可以使用/prefix/title-and-stuff-123456-foo.html格式的/prefix/title-and-stuff-123456-foo.html (即,整个URL看起来像http://mysrv.com/ctx/#/prefix/title-and-stuff-123.html ),继续阅读。

You can define the route as: /prefix/*titleAndId . 您可以将路由定义为: /prefix/*titleAndId Notice the * . 注意* Then the entire string is accessible inside any controller as $route.current.params.titleAndId . 然后,整个字符串都可以在$route.current.params.titleAndId内的任何控制器中$route.current.params.titleAndId You can parse this string (using an appropriate regular expression perhaps) and extract any information, then load the appropriate content. 您可以解析此字符串(也许使用适当的正则表达式)并提取任何信息,然后加载适当的内容。

The * in the route definition enables the argument to contain slashes too. 路由定义中的*使参数也可以包含斜杠。 If slashes are not required, you can use /prefix/:titleAndId and use it the same way. 如果不需要斜杠,则可以使用/prefix/:titleAndId并以相同的方式使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM