@@ -8,13 +8,39 @@ const addTrailingSlash = (uri: string) => {
8
8
return uri
9
9
}
10
10
11
- if ( uri . indexOf ( '#' ) > 0 ) {
12
- const hash = uri . substring ( uri . indexOf ( '#' ) , uri . length )
13
- uri = addSlash ( uri . replace ( hash , '' ) )
14
- return uri + hash
11
+ const removeSlash = ( uri : string ) => {
12
+ return uri . replace ( / \/ $ / , '' )
15
13
}
14
+
15
+ const getHash = ( uri : string ) => {
16
+ if ( uri . indexOf ( '#' ) > 0 ) {
17
+ return uri . substring ( uri . indexOf ( '#' ) , uri . length )
18
+ }
19
+ return ''
20
+ }
21
+
22
+ const getSearch = ( uri : string ) => {
23
+ if ( uri . indexOf ( '?' ) > 0 ) {
24
+ return uri . substring ( uri . indexOf ( '?' ) , uri . length )
25
+ }
26
+ return ''
27
+ }
28
+
29
+ // eg: http://localhost:8001/playground/?deploy=node-template#config
30
+ // remove back slash if exist
31
+ uri = removeSlash ( uri )
32
+ // store hash if exist and remove from uri
33
+ const hash = getHash ( uri )
34
+ if ( hash ) uri = uri . replace ( hash , '' )
35
+ // remove back slash if exist
36
+ uri = removeSlash ( uri )
37
+ // store search query if exist and remove from uri
38
+ const search = getSearch ( uri )
39
+ if ( search ) uri = uri . replace ( search , '' )
40
+ // add slash if missing
16
41
uri = addSlash ( uri )
17
- return uri
42
+
43
+ return uri + search + hash
18
44
}
19
45
20
46
interface InfraLinkProps {
0 commit comments