-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.js
36 lines (32 loc) · 818 Bytes
/
demo.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
dojo.provide('demo');
dojo.require("urldispatch");
// Set up routes
dojo.ready(function(){
var routes = [
['!/', home_view, 'home'],
['!/Hello', hello_view],
['!/Hello/:name', hello_view, 'hello']
];
var dispatcher = new urldispatch.Dispatcher(routes, {
notFoundHandler: function(request){
console.log(request);
}
});
});
// Some views
function home_view(request){
alert('Welcome!');
}
function hello_view(request){
if(!request.name){
alert('Hey, anonymous!');
return;
}
var status = window.confirm('Hey, are you ' + request.name + '?');
if(status){
alert('Tere ' + request.name + '!');
}else{
var url = request.dispatcher.reverse('home');
request.dispatcher.redirect(url);
}
}