fix(navigation): resolve clicked anchor when target is a nested element
A click on a child of an <a> (e.g. nested <strong>, <em>, <code>, icon)
made event.target a non-anchor, so getAttribute('href') returned null
and the handler bailed without preventDefault. The browser then
performed the native navigation, which for relative links like
'../note.md' resolved against the current /:user/:repo URL and the SPA
re-routed treating the destination as a new repo.
This commit is contained in:
@@ -17,8 +17,8 @@ export const useATProtoLinks = (
|
|||||||
const { currentAtUri, mainNoteId } = options
|
const { currentAtUri, mainNoteId } = options
|
||||||
|
|
||||||
const linkNote = (event: Event) => {
|
const linkNote = (event: Event) => {
|
||||||
const target = event.target as HTMLElement
|
const anchor = (event.target as HTMLElement).closest("a")
|
||||||
const href = target.getAttribute("href")
|
const href = anchor?.getAttribute("href")
|
||||||
|
|
||||||
if (!href) {
|
if (!href) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ export const useLinks = (
|
|||||||
const store = useUserRepoStore()
|
const store = useUserRepoStore()
|
||||||
|
|
||||||
const linkNote: EventListener = (event) => {
|
const linkNote: EventListener = (event) => {
|
||||||
const target = event.target as HTMLElement
|
const anchor = (event.target as HTMLElement).closest("a")
|
||||||
const href = target.getAttribute("href")
|
const href = anchor?.getAttribute("href")
|
||||||
|
|
||||||
if (!href) {
|
if (!href) {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user