-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
95 lines (75 loc) · 2.4 KB
/
example.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
// Create external object to be invoked as route handlers
var obj = {
foo: function(go, target){
console.log('External \'foo\'');
},
bar: function(go, target){
console.log('External \'bar\'');
}
};
go(
// Route mappings
{
// Run this function before every route is executed
before: function(){
console.log('before');
},
// Function literal
"/hello.htm": function(go, target){
console.log('Hello World!');
},
// Path to controller as string (must be a string if the controller is passed in as a literal JSON map)
// String route definitions will not perform as well as function literals or external object/methohd references
"/index.htm": "app.home",
// Route config map to specify handler, navigator, and subroutes
"/search.htm": {
// Handler to invoke
handler: "app.search",
// Shortcut name for this route
navigator: "basicSearch",
// Subroutes
subroutes: {
"#advanced": {
handler: "app.advancedSearch",
navigator: "advancedSearch"
}
}
},
"/results.htm": {
handler: "app.results",
navigator: "results"
},
// External object/function
"/external.htm": obj.foo,
// Run this function after every route is executed
after: function(){
console.log('after');
}
},
// Controllers
{
app: {
home: function(go, target){
console.log('home');
// Invoke basic search handler via redirect
go.to('basicSearch', true);
},
search: function(go, target){
console.log('search');
go.to('advancedSearch');
},
advancedSearch: function(go, target){
console.log('advancedSearch');
obj.bar();
},
results: function(go, target){
console.log('results');
}
}
},
// Options
{
rootPath: '/test',
bindHashClicks: true
}
).to(window.location);