@@ -111,13 +111,22 @@ 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
+ // Convert
120
121
122
+ const toAbsoluteURL = ( url : string ) : string => {
123
+ return new URL ( url , window . location . href ) . href ;
124
+ } ;
125
+ const isHashAnchor = ( currentUrl : string , newUrl : string ) : boolean => {
126
+ const current = new URL ( toAbsoluteURL ( currentUrl ) ) ;
127
+ const next = new URL ( toAbsoluteURL ( newUrl ) ) ;
128
+ return current . href . split ( '#' ) [ 0 ] === next . href . split ( '#' ) [ 0 ] ;
129
+ } ;
121
130
React . useEffect ( ( ) => {
122
131
NProgress . configure ( {
123
132
showSpinner : showSpinner ?? true ,
@@ -167,9 +176,19 @@ const NextTopLoader = ({
167
176
const currentUrl = window . location . href ;
168
177
// const newUrl = (anchor as HTMLAnchorElement).href;
169
178
const isExternalLink = ( anchor as HTMLAnchorElement ) . target === '_blank' ;
170
- const isBlob = newUrl . startsWith ( 'blob:' ) ;
179
+ const isSpecialScheme = [ 'tel:' , 'mailto:' , 'sms:' , 'blob:' , 'download:' ] . some ( ( scheme ) =>
180
+ newUrl . startsWith ( scheme )
181
+ ) ;
171
182
const isAnchor = isAnchorOfCurrentUrl ( currentUrl , newUrl ) ;
172
- if ( newUrl === currentUrl || isAnchor || isExternalLink || isBlob || event . ctrlKey || event . metaKey ) {
183
+ if (
184
+ newUrl === currentUrl ||
185
+ isAnchor ||
186
+ isExternalLink ||
187
+ isSpecialScheme ||
188
+ event . ctrlKey ||
189
+ event . metaKey ||
190
+ isHashAnchor ( window . location . href , anchor . href )
191
+ ) {
173
192
NProgress . start ( ) ;
174
193
NProgress . done ( ) ;
175
194
[ ] . forEach . call ( npgclass , function ( el : Element ) {
0 commit comments