$routeProvider
service in module ngRoute
Description
Used for configuring routes.
Example
See $route for an example of configuring and using ngRoute
.
Dependencies
Requires the ngRoute
module to be installed.
Methods
Sets route definition that will be used on route change when no other route definition is matched.
Parameters
ParamTypeDetailsparamsObject
Mapping information to be assigned to $route.current
.
Returns
self
Adds a new route definition to the $route
service.
Parameters
ParamTypeDetailspathstring
Route path (matched against $location.path
). If $location.path
contains redundant trailing slash or is missing one, the route will still match and the $location.path
will be updated to add or drop the trailing slash to exactly match the route definition.
path
can contain named groups starting with a colon (:name
). All characters up to the next slash are matched and stored in$routeParams
under the givenname
when the route matches.path
can contain named groups starting with a colon and ending with a star (:name*
). All characters are eagerly stored in$routeParams
under the givenname
when the route matches.path
can contain optional named groups with a question mark (:name?
).
For example, routes like/color/:color/largecode/:largecode*\/edit
will match/color/brown/largecode/code/with/slashs/edit
and extract:color: brown
largecode: code/with/slashs
.
routeObject
Mapping information to be assigned to $route.current
on route match.
Object properties:
controller
–{(string|function()=}
– Controller fn that should be associated with newly created scope or the name of aregistered controller
if passed as a string.controllerAs
–{string=}
– A controller alias name. If present the controller will be published to scope under thecontrollerAs
name.template
–{string=|function()=}
– html template as a string or a function that returns an html template as a string which should be used by ngView orngInclude
directives. This property takes precedence overtemplateUrl
.
If template
is a function, it will be called with the following parameters:
- <code>{Array.<object>}</object></code> - route parameters extracted from the current <code>$location.path()</code> by applying the current route
templateUrl
–{string=|function()=}
– path or function that returns a path to an html template that should be used by ngView.
If templateUrl
is a function, it will be called with the following parameters:
- <code>{Array.<object>}</object></code> - route parameters extracted from the current <code>$location.path()</code> by applying the current route
resolve
-{Object.
- An optional map of dependencies which should be injected into the controller. If any of these dependencies are promises, the router will wait for them all to be resolved or one to be rejected before the controller is instantiated. If all the promises are resolved successfully, the values of the resolved promises are injected and $routeChangeSuccess event is fired. If any of the promises are rejected the $routeChangeError event is fired. The map object is:=} key
–{string}
: a name of a dependency to be injected into the controller.factory
-{string|function}
: Ifstring
then it is an alias for a service. Otherwise if function, then it isinjected
and the return value is treated as the dependency. If the result is a promise, it is resolved before its value is injected into the controller. Be aware thatngRoute.$routeParams
will still refer to the previous route within these resolve functions. Use$route.current.params
to access the new route parameters, instead.
redirectTo
– {(string|function())=} – value to update$location
path with and trigger route redirection.
If redirectTo
is a function, it will be called with the following parameters:
- <code>{Object.<string>}</string></code> - route parameters extracted from the current <code>$location.path()</code> by applying the current route templateUrl.
- <code>{string}</code> - current <code>$location.path()</code>
- <code>{Object}</code> - current <code>$location.search()</code>
The custom redirectTo
function is expected to return a string which will be used to update $location.path()
and $location.search()
.
[reloadOnSearch=true]
- {boolean=} - reload route when only$location.search()
or$location.hash()
changes.
If the option is set to false
and url in the browser changes, then $routeUpdate
event is broadcasted on the root scope.
[caseInsensitiveMatch=false]
- {boolean=} - match routes without being case sensitive
If the option is set to true
, then the particular route can be matched without being case sensitive
Returns
self