-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstates.js
109 lines (95 loc) · 3.36 KB
/
states.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import App from '../main/App';
import Welcome from '../main/Welcome';
import Login from '../main/Login';
import Home from '../main/Home';
/**
* This is the parent state for the entire application.
*
* This state's primary purposes are:
* 1) Shows the outermost chrome (including the navigation and logout for authenticated users)
* 2) Provide a viewport (ui-view) for a substate to plug into
*/
const appState = {
name: 'app',
redirectTo: 'welcome',
component: App
}
/**
* This is the 'welcome' state. It is the default state (as defined by app.js) if no other state
* can be matched to the URL.
*/
const welcomeState = {
parent: 'app',
name: 'welcome',
url: '/welcome',
component: Welcome
}
/**
* This is a home screen for authenticated users.
*
* It shows giant buttons which activate their respective submodules: Messages, Contacts, Preferences
*/
const homeState = {
parent: 'app',
name: 'home',
url: '/home',
component: Home
};
/**
* This is the login state. It is activated when the user navigates to /login, or if a unauthenticated
* user attempts to access a protected state (or substate) which requires authentication. (see routerhooks/requiresAuth.js)
*
* It shows a fake login dialog and prompts the user to authenticate. Once the user authenticates, it then
* reactivates the state that the user originally came from.
*/
const loginState = {
parent: 'app',
name: 'login',
url: '/login',
component: Login,
resolve: { returnTo: returnTo }
};
/**
* A resolve function for 'login' state which figures out what state to return to, after a successful login.
*
* If the user was initially redirected to login state (due to the requiresAuth redirect), then return the toState/params
* they were redirected from. Otherwise, if they transitioned directly, return the fromState/params. Otherwise
* return the main "app" state.
*/
function returnTo ($transition$) {
if ($transition$.redirectedFrom()) {
// The user was redirected to the login state (e.g., via the requiresAuth hook when trying to activate contacts)
// Return to the original attempted target state (e.g., contacts)
return $transition$.redirectedFrom().targetState();
}
let $state = $transition$.router.stateService;
// The user was not redirected to the login state; they directly activated the login state somehow.
// Return them to the state they came from.
if ($transition$.from().name !== '') {
return $state.target($transition$.from(), $transition$.params("from"));
}
// If the fromState's name is empty, then this was the initial transition. Just return them to the home state
return $state.target('home');
}
// Future State (Placeholder) for the contacts module
export const contactsFutureState = {
parent: 'app',
name: 'contacts.**',
url: '/contacts',
lazyLoad: () => System.import('../contacts/states'),
};
// Future State (Placeholder) for the prefs module
export const prefsFutureState = {
parent: 'app',
name: 'prefs.**',
url: '/prefs',
lazyLoad: () => System.import('../prefs/states'),
};
// Future State (Placeholder) for the mymessages module
export const mymessagesFutureState = {
parent: 'app',
name: 'mymessages.**',
url: '/mymessages',
lazyLoad: () => System.import('../mymessages/states'),
};
export default [appState, welcomeState, homeState, loginState, contactsFutureState, prefsFutureState, mymessagesFutureState];