@@ -107,32 +107,10 @@ where
107107 app
108108}
109109
110- <<<<<<< HEAD
110+
111111fn remove_first ( s : & str ) -> Option < & str > {
112112 s. chars ( ) . next ( ) . map ( |c| & s[ c. len_utf8 ( ) ..] )
113113}
114- =======
115- pub fn setup_popstate_listener < Ms , Mdl > ( app : & App < Ms , Mdl > , routes : fn ( & Url ) -> Ms )
116- where
117- Ms : Clone ,
118- {
119- // We can't reuse the app later to store the popstate once moved into the closure.
120- let app_for_closure = app. clone ( ) ;
121- let closure = Closure :: wrap ( Box :: new ( move |ev: web_sys:: Event | {
122- let ev = ev
123- . dyn_ref: : < web_sys:: PopStateEvent > ( )
124- . expect( "Problem casting as Popstate event" ) ;
125-
126- let url : Url = match ev. state ( ) . as_string( ) {
127- Some ( state_str) => serde_json:: from_str ( & state_str )
128- . expect( "Problem deserialzing popstate state" ) ,
129- // This might happen if we go back to a page before we started routing. (?)
130- None => {
131- let empty: Vec < String > = Vec :: new( ) ;
132- Url :: new( empty)
133- }
134- } ;
135- >>>>>>> e449e6645f76720a29d6dfa7971198381acc247c
136114
137115fn clean_url ( mut url : Url ) -> Url {
138116 let mut cleaned_path = vec ! [ ] ;
@@ -174,8 +152,6 @@ pub fn push_route(mut url: Url) {
174152 // the existing path. Not doing so will add the path to the existing one.
175153 let path = String :: from ( "/" ) + & url. path . join ( "/" ) ;
176154
177- crate :: log( & path) ;
178-
179155 util:: window ( )
180156 . history ( )
181157 . expect ( "Can't find history" )
@@ -253,10 +229,12 @@ pub fn setup_link_listener<Ms: Clone, Mdl>(app: &App<Ms, Mdl>, routes: fn(&Url)
253229 }
254230 if let Some ( href) = el. get_attribute ( "href" ) {
255231 if let Some ( first) = href. chars ( ) . next ( ) {
232+ // The first character being / indicates a rel link, which is what
233+ // we're intercepting.
256234 if first == '/' {
257235 event. prevent_default ( ) ;
258- // Route internally based on href
259- let url = Url :: new( vec ! [ href] ) ;
236+ // Route internally based on href's value
237+ let url = Url :: new ( href. split ( '/' ) . collect ( ) ) ;
260238 app_for_closure. update ( routes ( & url) ) ;
261239 push_route ( url) ;
262240 }
0 commit comments