@@ -111,13 +111,24 @@ const NextTopLoader = ({
111
111
// Check if to show at bottom
112
112
const positionStyle = showAtBottom ? 'bottom: 0;' : 'top: 0;' ;
113
113
const spinnerPositionStyle = showAtBottom ? 'bottom: 15px;' : 'top: 15px;' ;
114
-
114
+
115
115
const styles = (
116
116
< style >
117
117
{ `#nprogress{pointer-events:none}#nprogress .bar{background:${ color } ;position:fixed;z-index:${ zIndex } ;${ positionStyle } left:0;width:100%;height:${ height } px}#nprogress .peg{display:block;position:absolute;right:0;width:100px;height:100%;${ boxShadow } ;opacity:1;-webkit-transform:rotate(3deg) translate(0px,-4px);-ms-transform:rotate(3deg) translate(0px,-4px);transform:rotate(3deg) translate(0px,-4px)}#nprogress .spinner{display:block;position:fixed;z-index:${ zIndex } ;${ spinnerPositionStyle } right:15px}#nprogress .spinner-icon{width:18px;height:18px;box-sizing:border-box;border:2px solid transparent;border-top-color:${ color } ;border-left-color:${ color } ;border-radius:50%;-webkit-animation:nprogress-spinner 400ms linear infinite;animation:nprogress-spinner 400ms linear infinite}.nprogress-custom-parent{overflow:hidden;position:relative}.nprogress-custom-parent #nprogress .bar,.nprogress-custom-parent #nprogress .spinner{position:absolute}@-webkit-keyframes nprogress-spinner{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg)}}@keyframes nprogress-spinner{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}` }
118
118
</ style >
119
119
) ;
120
120
121
+ // Convert the url to Absolute URL based on the current window location.
122
+ const toAbsoluteURL = ( url : string ) : string => {
123
+ return new URL ( url , window . location . href ) . href ;
124
+ } ;
125
+
126
+ // Check if it is hash anchor or same page anchor
127
+ const isHashAnchor = ( currentUrl : string , newUrl : string ) : boolean => {
128
+ const current = new URL ( toAbsoluteURL ( currentUrl ) ) ;
129
+ const next = new URL ( toAbsoluteURL ( newUrl ) ) ;
130
+ return current . href . split ( '#' ) [ 0 ] === next . href . split ( '#' ) [ 0 ] ;
131
+ } ;
121
132
React . useEffect ( ( ) => {
122
133
NProgress . configure ( {
123
134
showSpinner : showSpinner ?? true ,
@@ -167,9 +178,21 @@ const NextTopLoader = ({
167
178
const currentUrl = window . location . href ;
168
179
// const newUrl = (anchor as HTMLAnchorElement).href;
169
180
const isExternalLink = ( anchor as HTMLAnchorElement ) . target === '_blank' ;
170
- const isSpecialScheme = [ 'tel:' , 'mailto:' , 'sms:' , 'blob:' , 'download:' ] . some ( ( scheme ) => newUrl . startsWith ( scheme ) ) ;
181
+
182
+ // Check for Special Schemes
183
+ const isSpecialScheme = [ 'tel:' , 'mailto:' , 'sms:' , 'blob:' , 'download:' ] . some ( ( scheme ) =>
184
+ newUrl . startsWith ( scheme )
185
+ ) ;
171
186
const isAnchor = isAnchorOfCurrentUrl ( currentUrl , newUrl ) ;
172
- if ( newUrl === currentUrl || isAnchor || isExternalLink || isSpecialScheme || event . ctrlKey || event . metaKey ) {
187
+ if (
188
+ newUrl === currentUrl ||
189
+ isAnchor ||
190
+ isExternalLink ||
191
+ isSpecialScheme ||
192
+ event . ctrlKey ||
193
+ event . metaKey ||
194
+ isHashAnchor ( window . location . href , anchor . href )
195
+ ) {
173
196
NProgress . start ( ) ;
174
197
NProgress . done ( ) ;
175
198
[ ] . forEach . call ( npgclass , function ( el : Element ) {
0 commit comments