-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppRouter.js
112 lines (97 loc) · 2.89 KB
/
AppRouter.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
110
111
112
/**
* Created by momchillgorchev on 19/02/15.
*/
Router.configure({
layoutTemplate: "mainLayout",
loadingTemplate: "loading"
//notFoundTemplate: "missing"
});
UserAccessController = RouteController.extend({
//On before action hook to check if the user is logged in
onBeforeAction: function(){
var currentRoute = Router.current().options.route._path;
if (!(Meteor.loggingIn() || Meteor.user())) {
this.redirect("login");
} else{
// Subscriptions
Meteor.subscribe('favourites');
Meteor.subscribe('playlists');
Meteor.subscribe('apicalls');
if(currentRoute === '/rss'){
//Meteor.subscribe('rssfeed');
Meteor.subscribe('lastrss');
} else if(currentRoute === '/github'){
Meteor.subscribe('githubrecent');
} else if(currentRoute === '/twitter') {
Meteor.subscribe('tweets');
}
// After IR > 1.* you need to use this.next()
// for better use of connection middleware
this.next();
}
},
waitOn: function(){
var currentRoute = Router.current().options.route._path;
// Subscriptions
Meteor.subscribe('favourites');
Meteor.subscribe('playlists');
Meteor.subscribe('apicalls');
if(currentRoute === '/rss'){
Meteor.subscribe('rssfeed');
Meteor.subscribe('lastrss');
} else if(currentRoute === '/github'){
Meteor.subscribe('githubrecent');
} else if(currentRoute === '/twitter'){
Meteor.subscribe('tweets');
}
}
});
Router.map(function () {
this.route('home', {
path: '/',
controller: UserAccessController
});
this.route('profile', {
path: '/profile',
controller: UserAccessController
});
this.route('youtube', {
path: '/youtube',
controller: UserAccessController
});
this.route('favourites', {
path: '/favourites',
controller: UserAccessController
});
this.route('github', {
path: '/github',
controller: UserAccessController
});
this.route('twitter', {
path: '/twitter',
controller: UserAccessController
});
this.route('rss', {
path: '/rss',
controller: UserAccessController
});
this.route('playlists', {
path: 'playlists/:_id',
data: function(){
var result = Playlists.findOne({_id: this.params._id});
if(result){
return result;
}
},
controller: UserAccessController
});
this.route('login', {
path: '/login',
waitOn: function() {
if(Meteor.user()) {
this.redirect("home");
}
}
})
});
//console.log('FMM: Route map initiated -- OK');