0

I have the following routes that I'd like to match

/biblioteca
/biblioteca/whatever

So far now I made two routes, like this:

$routeProvider.when('/biblioteca', { ...
$routeProvider.when('/biblioteca/:path*', { ...

Is there some way to capture both of them with a single route, stating that the :path* part is optional? perhaps something like...

$routeProvider.when('/biblioteca/:?path*', { ...

what would be the correct way to handle such a case?

opensas
  • 60,462
  • 79
  • 252
  • 386
  • Possible duplicate of http://stackoverflow.com/questions/17510962/can-angularjs-routes-have-optional-parameter-values – ABOS Apr 13 '15 at 13:41

1 Answers1

1

Put the question mark after the named group.

$routeProvider.when('/biblioteca/:path?', { ...
  • path can contain optional named groups with a question mark: e.g.:name?.

See docs.angularjs.org/api/ngRoute/provider/$routeProvider

naeramarth7
  • 6,030
  • 1
  • 22
  • 26