https://github.com/murwa/ui-router-redirect
A simple implementation of `redirectTo` for ui-router
https://github.com/murwa/ui-router-redirect
angularjs redirect routing ui-router
Last synced: 7 months ago
JSON representation
A simple implementation of `redirectTo` for ui-router
- Host: GitHub
- URL: https://github.com/murwa/ui-router-redirect
- Owner: murwa
- License: mit
- Created: 2017-06-10T00:22:42.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-14T14:54:53.000Z (over 8 years ago)
- Last Synced: 2025-05-15T13:15:31.420Z (8 months ago)
- Topics: angularjs, redirect, routing, ui-router
- Language: JavaScript
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/murwa/ui-router-redirect)
## UI-Router Redirect
An angularjs module to easily handle redirects between states
### Installation
Bower:
~~~javascript
bower install ui-router-redirect
~~~
In your page, add:
~~~html
~~~
### Usage
#### Load module
Add the module as a dependency to your app:
~~~javascript
var app = angular.module('app', ['ui-router-redirect']
~~~
#### State Definition
Add `redirectTo` key on a state definition. The value could be:
- `string`: redirects to the state
~~~javascript
var state = {
name: 'string-redirect',
redirectTo: 'main' // Redirects to main state
}
~~~
- `object` : should have `state` and `params` keys. Will redirect to the named state with given parameters
~~~javascript
var state = {
name: 'string-redirect',
redirectTo: {state: 'main', params: {param1: true}} // Redirects to main state with params
}
~~~
- `function` : should return either `string`, `object` or `promise` - promise will be resolved (should resolve to either `string` or `object`)
~~~javascript
var state = {
name: 'string-redirect',
redirectTo: function(){
return 'main' // Redirects to main state
}
}
~~~
~~~javascript
// Promise example
var state = {
name: 'string-redirect',
redirectTo: ['$timeout', function($timeout){
return $timeout(function(){
return 'main' // Redirects to main state
});
}
}
~~~