@@ -323,7 +323,7 @@ function init() {
323323 } else {
324324 // Create new view with initializing
325325 getLocationsFromHash ( ) . forEach ( ( string , index ) => {
326- const dest = join ( decodeURIComponent ( string ) ) ;
326+ const dest = join ( string ) ;
327327 newView ( dest , index ) ;
328328 } ) ;
329329 }
@@ -1016,6 +1016,30 @@ function getViewLocation(view) {
10161016 }
10171017}
10181018
1019+ function encodeHashPath ( path ) {
1020+ // droppy will keep "/" separators intact by encoding segment by segment.
1021+ if ( typeof path !== "string" ) return path ;
1022+ return path
1023+ . split ( "/" )
1024+ . map ( ( seg ) => encodeURIComponent ( seg ) )
1025+ . join ( "/" ) ;
1026+ }
1027+
1028+ function decodeHashPath ( path ) {
1029+ // and do the reverse here, segment by segment
1030+ if ( typeof path !== "string" ) return path ;
1031+ return path
1032+ . split ( "/" )
1033+ . map ( ( seg ) => {
1034+ try {
1035+ return decodeURIComponent ( seg ) ;
1036+ } catch {
1037+ return seg ;
1038+ }
1039+ } )
1040+ . join ( "/" ) ;
1041+ }
1042+
10191043function getLocationsFromHash ( ) {
10201044 const locations = window . location . hash . split ( "#" ) ;
10211045 locations . shift ( ) ;
@@ -1027,6 +1051,7 @@ function getLocationsFromHash() {
10271051 locations . forEach ( ( part , i ) => {
10281052 locations [ i ] = part . replace ( / \/ * $ / g, "" ) ;
10291053 if ( locations [ i ] === "" ) locations [ i ] = "/" ;
1054+ locations [ i ] = decodeHashPath ( locations [ i ] ) ;
10301055 } ) ;
10311056 return locations ;
10321057}
@@ -1036,9 +1061,9 @@ function getHashPaths(modview, dest) {
10361061 droppy . views . forEach ( ( view ) => {
10371062 view = $ ( view ) ;
10381063 if ( modview ?. is ( view ) ) {
1039- path += `/#${ dest } ` ;
1064+ path += `/#${ encodeHashPath ( dest ) } ` ;
10401065 } else {
1041- path += `/#${ getViewLocation ( view ) } ` ;
1066+ path += `/#${ encodeHashPath ( getViewLocation ( view ) ) } ` ;
10421067 }
10431068 } ) ;
10441069 return path . replace ( / \/ + / g, "/" ) ;
0 commit comments