@@ -80,6 +80,12 @@ export type NextTopLoaderProps = {
80
80
*
81
81
*/
82
82
showAtBottom ?: boolean ;
83
+ /**
84
+ * To show the TopLoader for hash anchors.
85
+ * @default true
86
+ *
87
+ */
88
+ showForHashAnchor ?: boolean ;
83
89
} ;
84
90
85
91
/**
@@ -104,6 +110,7 @@ const NextTopLoader = ({
104
110
template,
105
111
zIndex = 1600 ,
106
112
showAtBottom = false ,
113
+ showForHashAnchor = true ,
107
114
} : NextTopLoaderProps ) : React . JSX . Element => {
108
115
const defaultColor = '#29d' ;
109
116
const defaultHeight = 3 ;
@@ -241,21 +248,26 @@ const NextTopLoader = ({
241
248
newUrl . startsWith ( scheme )
242
249
) ;
243
250
244
- const isAnchor : boolean = isAnchorOfCurrentUrl ( currentUrl , newUrl ) ;
245
251
const notSameHost = ! isSameHostName ( window . location . href , anchor . href ) ;
246
252
if ( notSameHost ) {
247
253
return ;
248
254
}
255
+
256
+ const isAnchorOrHashAnchor =
257
+ isAnchorOfCurrentUrl ( currentUrl , newUrl ) || isHashAnchor ( window . location . href , anchor . href ) ;
258
+ if ( ! showForHashAnchor && isAnchorOrHashAnchor ) {
259
+ return ;
260
+ }
261
+
249
262
if (
250
263
newUrl === currentUrl ||
251
- isAnchor ||
252
264
isExternalLink ||
253
265
isSpecialScheme ||
266
+ isAnchorOrHashAnchor ||
254
267
event . ctrlKey ||
255
268
event . metaKey ||
256
269
event . shiftKey ||
257
270
event . altKey ||
258
- isHashAnchor ( window . location . href , anchor . href ) ||
259
271
! toAbsoluteURL ( anchor . href ) . startsWith ( 'http' )
260
272
) {
261
273
NProgress . start ( ) ;
@@ -288,10 +300,10 @@ const NextTopLoader = ({
288
300
} ) ( ( window as Window ) . history ) ;
289
301
290
302
/**
291
- * Complete TopLoader Progress on replacing current entry of history stack
292
- * @param {History }
293
- * @returns {void }
294
- */
303
+ * Complete TopLoader Progress on replacing current entry of history stack
304
+ * @param {History }
305
+ * @returns {void }
306
+ */
295
307
( ( history : History ) : void => {
296
308
const replaceState = history . replaceState ;
297
309
history . replaceState = ( ...args ) => {
0 commit comments