mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 08:59:38 +08:00
DataLinks: Ensure window origin to be stripped from url when using absolute urls (#32634)
* Ensure window origin to be stripped from url when using absolute urls * Update test * Make sure link interception works for external links * Apply suggestions from code review * Review
This commit is contained in:
@ -19,11 +19,20 @@ export function interceptLinkClicks(e: MouseEvent) {
|
||||
|
||||
href = locationUtil.stripBaseFromUrl(href);
|
||||
// Ensure old angular urls with no starting '/' are handled the same as before
|
||||
// Make sure external links are handled correctly
|
||||
// That is they where seen as being absolute from app root
|
||||
if (href[0] !== '/') {
|
||||
try {
|
||||
const external = new URL(href);
|
||||
if (external.origin !== window.location.origin) {
|
||||
window.location.href = external.toString();
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
href = `/${href}`;
|
||||
}
|
||||
|
||||
locationService.push(href);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user