3
3
*/
4
4
5
5
import React from 'react' ;
6
- import { Router , Route , Link } from 'react-router' ;
6
+ import { Router , Route , IndexRoute , Link } from 'react-router' ;
7
7
import CommentBox from '../../components/comment/CommentBox.js' ;
8
8
import CommentForm from '../../components/comment/CommentForm.js' ;
9
9
import RSVP from '../../components/utils/common.js' ;
@@ -22,19 +22,48 @@ var App = React.createClass({
22
22
}
23
23
} ) ;
24
24
25
- /*reply/:id/:towho/:towhoname*/
25
+ var AppDefault = React . createClass ( {
26
+ render : function ( ) {
27
+ return null ;
28
+ }
29
+ } ) ;
30
+
31
+ var onEnterRoot = function ( nextState , replaceState ) {
32
+ //console.log("onEnterRoot");
33
+ //console.log("nextState",nextState);
34
+ //console.log("replaceState",replaceState);
35
+ var hash = nextState . location . pathname . replace ( '/' , '#' ) ;
36
+ if ( hash ) { console . log ( "hash=" , hash ) ;
37
+ var element = document . querySelector ( hash ) ;
38
+ if ( element ) { console . log ( "scrollIntoView" ) ;
39
+ element . scrollIntoView ( ) ;
40
+ }
41
+ } else {
42
+ window . scrollTo ( 0 , 0 ) ;
43
+ }
44
+ } ;
45
+
46
+
47
+ var onTouchMove = function ( e ) { //console.log('onTouchMove');
48
+ e . preventDefault ( ) ;
49
+ e . stopPropagation ( ) ;
50
+ } ;
26
51
var onEnter = function ( ) {
27
52
console . log ( "onEnter" ) ;
53
+ document . body . addEventListener ( 'touchmove' , onTouchMove , false ) ;
28
54
} ;
29
55
var onLeave = function ( ) {
30
56
console . log ( "onLeave" ) ;
57
+ document . body . removeEventListener ( 'touchmove' , onTouchMove ) ;
31
58
} ;
32
- React . render ( (
33
- < Router >
34
- < Route path = "/" component = { App } >
35
- < Route path = "post" component = { CommentForm } onEnter = { onEnter } onLeave = { onLeave } />
36
- < Route path = "reply/:id" component = { CommentForm } onEnter = { onEnter } onLeave = { onLeave } />
37
- </ Route >
38
- </ Router >
39
- ) , document . getElementById ( "comments" )
59
+ var routes = < Route path = "/" component = { App } onEnter = { onEnterRoot } >
60
+ /*< IndexRoute component = { AppDefault } /> */
61
+ < Route path = "post" component = { CommentForm } onEnter = { onEnter } onLeave = { onLeave } />
62
+ < Route path = "reply/:id" component = { CommentForm } onEnter = { onEnter } onLeave = { onLeave } />
63
+ < Route path = "*" component = { AppDefault } />
64
+ </ Route > ;
65
+
66
+ var router = < Router routes = { routes } />
67
+ /*reply/:id/:towho/:towhoname*/
68
+ React . render ( router , document . getElementById ( "comments" )
40
69
) ;
0 commit comments