@@ -80,6 +80,12 @@ export type NextTopLoaderProps = {
8080 *
8181 */
8282 showAtBottom ?: boolean ;
83+ /**
84+ * To show the TopLoader for hash anchors.
85+ * @default true
86+ *
87+ */
88+ showForHashAnchor ?: boolean ;
8389} ;
8490
8591/**
@@ -104,6 +110,7 @@ const NextTopLoader = ({
104110 template,
105111 zIndex = 1600 ,
106112 showAtBottom = false ,
113+ showForHashAnchor = true ,
107114} : NextTopLoaderProps ) : React . JSX . Element => {
108115 const defaultColor = '#29d' ;
109116 const defaultHeight = 3 ;
@@ -241,21 +248,26 @@ const NextTopLoader = ({
241248 newUrl . startsWith ( scheme )
242249 ) ;
243250
244- const isAnchor : boolean = isAnchorOfCurrentUrl ( currentUrl , newUrl ) ;
245251 const notSameHost = ! isSameHostName ( window . location . href , anchor . href ) ;
246252 if ( notSameHost ) {
247253 return ;
248254 }
255+
256+ const isAnchorOrHashAnchor =
257+ isAnchorOfCurrentUrl ( currentUrl , newUrl ) || isHashAnchor ( window . location . href , anchor . href ) ;
258+ if ( ! showForHashAnchor && isAnchorOrHashAnchor ) {
259+ return ;
260+ }
261+
249262 if (
250263 newUrl === currentUrl ||
251- isAnchor ||
252264 isExternalLink ||
253265 isSpecialScheme ||
266+ isAnchorOrHashAnchor ||
254267 event . ctrlKey ||
255268 event . metaKey ||
256269 event . shiftKey ||
257270 event . altKey ||
258- isHashAnchor ( window . location . href , anchor . href ) ||
259271 ! toAbsoluteURL ( anchor . href ) . startsWith ( 'http' )
260272 ) {
261273 NProgress . start ( ) ;
@@ -288,10 +300,10 @@ const NextTopLoader = ({
288300 } ) ( ( window as Window ) . history ) ;
289301
290302 /**
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+ */
295307 ( ( history : History ) : void => {
296308 const replaceState = history . replaceState ;
297309 history . replaceState = ( ...args ) => {
0 commit comments