0

in AngularJS can I set up a style route like this:

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

where '123546' is an indentifier ?

with:

$locationProvider.html5Mode(true);

I must make this because I need keep the old URLs

aloon
  • 403
  • 7
  • 17

1 Answers1

0

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 (i.e. the entire URL would look like http://mysrv.com/ctx/#/prefix/title-and-stuff-123.html), read on.

You can define the route as: /prefix/*titleAndId. Notice the *. Then the entire string is accessible inside any controller as $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.

Nikos Paraskevopoulos
  • 39,514
  • 12
  • 85
  • 90