Skip to content

Commit

Permalink
refactor: remove extra methods
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Jan 7, 2024
1 parent e65f531 commit a6fe43d
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 182 deletions.
13 changes: 0 additions & 13 deletions e2e/docs/routes/get-pages-path.md

This file was deleted.

18 changes: 0 additions & 18 deletions e2e/docs/routes/is-page-exist.md

This file was deleted.

9 changes: 0 additions & 9 deletions e2e/docs/routes/resolve.md

This file was deleted.

45 changes: 0 additions & 45 deletions e2e/tests/routes/get-pages-path.cy.ts

This file was deleted.

22 changes: 0 additions & 22 deletions e2e/tests/routes/is-page-exisit.cy.ts

This file was deleted.

10 changes: 0 additions & 10 deletions e2e/tests/routes/resolve.cy.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/client/src/components/Content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const Content = defineComponent({
name: 'Content',

props: {
url: {
path: {
type: String,
required: false,
default: '',
Expand All @@ -19,7 +19,7 @@ export const Content = defineComponent({
setup(props) {
const page = usePageData()
const pageComponent = computed(
() => pagesMap.value.get(props.url || page.value.path)?.comp,
() => pagesMap.value.get(props.path || page.value.path)?.comp,
)
return () =>
pageComponent.value
Expand Down
30 changes: 26 additions & 4 deletions packages/client/src/components/VPLink.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import { h } from 'vue'
import type { FunctionalComponent, VNode } from 'vue'
import { useRouter } from 'vue-router'
import { resolve, withBase } from '../helpers/index.js'
import { guardEvent } from '../utils/index.js'
import { pagesMap, redirectsMap } from '../composables/index.js'
import { withBase } from '../helpers/index.js'
import { resolvers } from '../resolvers.js'

export interface VPLinkProps {
/**
* Forked from https://github.com/vuejs/router/blob/941b2131e80550009e5221d4db9f366b1fea3fd5/packages/router/src/RouterLink.ts#L293
*/
const guardEvent = (event: MouseEvent): boolean | void => {
// don't redirect with control keys
if (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey) return
// don't redirect when preventDefault called
if (event.defaultPrevented) return
// don't redirect on right click
if (event.button !== undefined && event.button !== 0) return
// don't redirect if `target="_blank"`
if (event.currentTarget) {
const target = (event.currentTarget as HTMLElement).getAttribute('target')
if (target?.match(/\b_blank\b/i)) return
}
event.preventDefault()
return true
}

interface VPLinkProps {
to: string
}

Expand All @@ -16,7 +36,9 @@ export const VPLink: FunctionalComponent<
}
> = ({ to = '' }, { slots }) => {
const router = useRouter()
const path = withBase(resolve(to).path)
const path = withBase(
resolvers.resolvePagePath(pagesMap.value, redirectsMap.value, to),
)

return h(
'a',
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './defineClientConfig.js'
export * from './router.js'
export * from './withBase.js'
38 changes: 0 additions & 38 deletions packages/client/src/helpers/router.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/client/src/utils/index.ts

This file was deleted.

19 changes: 0 additions & 19 deletions packages/client/src/utils/routeGuardEvent.ts

This file was deleted.

0 comments on commit a6fe43d

Please sign in to comment.