@@ -2,39 +2,28 @@ var app = angular.module('app', ['ngRoute','ngCookies'])
2
2
3
3
app . config ( function ( $routeProvider ) {
4
4
var $cookies ;
5
- angular . injector ( [ 'ngCookies' ] ) . invoke ( [ '$cookies' , function ( _$cookies_ ) {
6
- $cookies = _$cookies_ ;
5
+ angular . injector ( [ 'ngCookies' ] ) . invoke ( [ '$cookies' , function ( cookies ) {
6
+ $cookies = cookies ;
7
7
} ] )
8
- $routeProvider . when ( '/' , {
9
- templateUrl : $cookies . get ( 'user_id' ) ? 'partials/home.html' : 'partials/users/entrance.html' ,
10
- controller : 'users_cxr'
11
- } )
12
- $routeProvider . when ( '/login' , {
13
- templateUrl : 'partials/users/entrance.html' ,
14
- controller : 'users_cxr'
15
- } )
8
+ if ( $cookies . get ( 'user_id' ) ) {
9
+ $routeProvider . when ( '/home' , {
10
+ templateUrl : 'partials/home.html' ,
11
+ controller : 'users_cxr'
12
+ } )
13
+ $routeProvider . otherwise ( {
14
+ redirectTo : '/home'
15
+ } )
16
+ } else {
17
+ $routeProvider . when ( '/login' , {
18
+ templateUrl : 'partials/users/entrance.html' ,
19
+ controller : 'users_cxr'
20
+ } )
21
+ $routeProvider . otherwise ( {
22
+ redirectTo : '/login'
23
+ } )
24
+ }
16
25
$routeProvider . when ( '/users' , {
17
26
templateUrl : 'partials/users/index.html' ,
18
27
controller : 'users_cxr'
19
28
} )
20
- $routeProvider . when ( '/home' , {
21
- templateUrl : 'partials/home.html' ,
22
- controller : 'users_cxr'
23
- } )
24
- // $routeProvider.when('/users/show/:id',{
25
- // templateUrl : 'partials/users/show.html',
26
- // controller : 'users_cxr'
27
- // })
28
- // $routeProvider.when('/users/edit/:id',{
29
- // templateUrl : 'partials/users/edit.html',
30
- // controller : 'users_cxr'
31
- // })
32
- $routeProvider . otherwise ( {
33
- redirectTo : '/'
34
- } )
35
- } )
36
-
37
- // myApp.config(function() {
38
-
39
- // // here you can use $cookies as usual
40
- // });
29
+ } )
0 commit comments