-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4834 from FlowFuse/use-default-behavior-for-platf…
…orm-wide-anchors Use default behavior for platform wide anchors (part I)
- Loading branch information
Showing
16 changed files
with
204 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useRouter } from 'vue-router' | ||
|
||
export function useNavigationHelper () { | ||
const _router = useRouter() | ||
|
||
const openInANewTab = (href) => { | ||
return new Promise(resolve => { | ||
window.open(href, '_blank') | ||
resolve() | ||
}) | ||
} | ||
|
||
const _isExternalLink = (href) => { | ||
try { | ||
const link = new URL(href, window.location.origin) | ||
|
||
return link.origin !== window.location.origin | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
const navigateTo = (to, $event = null) => { | ||
const internalHref = _router.resolve(to).href | ||
const isMiddleButtonClick = $event?.button === 1 | ||
const newTabKeyCombination = $event && ($event?.ctrlKey || $event.metaKey || isMiddleButtonClick) | ||
const isExternalLink = _isExternalLink(to) | ||
|
||
switch (true) { | ||
case isExternalLink && newTabKeyCombination: | ||
return openInANewTab(to) | ||
|
||
case isExternalLink: | ||
return navigateToExternal(to) | ||
|
||
case newTabKeyCombination: | ||
return openInANewTab(internalHref) | ||
|
||
default: | ||
return _router.push(to) | ||
} | ||
} | ||
|
||
const navigateToExternal = (href) => { | ||
return new Promise(resolve => { | ||
window.location.href = href | ||
resolve() | ||
}) | ||
} | ||
|
||
return { | ||
openInANewTab, | ||
navigateTo, | ||
navigateToExternal | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.