Skip to content

Commit 6b73541

Browse files
committed
canary 2 unstable
1 parent 5fc1da3 commit 6b73541

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/index.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,22 @@ const NextTopLoader = ({
111111
// Check if to show at bottom
112112
const positionStyle = showAtBottom ? 'bottom: 0;' : 'top: 0;';
113113
const spinnerPositionStyle = showAtBottom ? 'bottom: 15px;' : 'top: 15px;';
114-
114+
115115
const styles = (
116116
<style>
117117
{`#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)}}`}
118118
</style>
119119
);
120+
// Convert
120121

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+
};
121130
React.useEffect(() => {
122131
NProgress.configure({
123132
showSpinner: showSpinner ?? true,
@@ -167,9 +176,19 @@ const NextTopLoader = ({
167176
const currentUrl = window.location.href;
168177
// const newUrl = (anchor as HTMLAnchorElement).href;
169178
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+
);
171182
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+
) {
173192
NProgress.start();
174193
NProgress.done();
175194
[].forEach.call(npgclass, function (el: Element) {

0 commit comments

Comments
 (0)