-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d39d8ce
commit cb94539
Showing
11 changed files
with
330 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { returnIfTrue } from '../../../../utils'; | ||
import { moduleOptionStore } from '../../../config'; | ||
|
||
export function createUseTypedLinkFile(): string { | ||
const strictOptions = moduleOptionStore.getResolvedStrictOptions(); | ||
const { pathCheck } = moduleOptionStore; | ||
|
||
return /* typescript */ ` | ||
import { useLink as defaultLink } from '#imports'; | ||
import type {MaybeRef} from 'vue'; | ||
import type { NavigateToOptions } from 'nuxt/dist/app/composables/router'; | ||
import type { NavigationFailure } from 'vue-router'; | ||
import type { TypedRouteLocationRawFromName, TypedRouteFromName, TypedRoute } from './__router'; | ||
import type { RoutesNamesList } from './__routes'; | ||
${returnIfTrue( | ||
pathCheck, | ||
`import type {TypedPathParameter, RouteNameFromPath} from './__paths';` | ||
)} | ||
type LinkedRoute<T extends RoutesNamesList> = { | ||
route: ComputedRef<TypedRouteFromName<T> & { | ||
href: string; | ||
}>; | ||
href: ComputedRef<string>; | ||
isActive: ComputedRef<boolean>; | ||
isExactActive: ComputedRef<boolean>; | ||
navigate: (e?: MouseEvent) => Promise<void | NavigationFailure>; | ||
}; | ||
interface UseLinkFunction { | ||
<T extends RoutesNamesList, P extends string>( | ||
props: { | ||
to: MaybeRef<TypedRouteLocationRawFromName<T, P>>, | ||
replace?: MaybeRef<boolean> | ||
} | ||
) : LinkedRoute<T> | ||
${returnIfTrue( | ||
pathCheck && !strictOptions.router.strictToArgument, | ||
`<T extends string>( | ||
props: { | ||
to: MaybeRef<TypedPathParameter<T>>, | ||
replace?: MaybeRef<boolean> | ||
} | ||
) : LinkedRoute<RouteNameFromPath<T>>` | ||
)} | ||
} | ||
/** | ||
* Typed clone of \`useLink\` | ||
* | ||
* @exemple | ||
* | ||
* \`\`\`ts | ||
* const router = useLink(props); | ||
* \`\`\` | ||
*/ | ||
export const useLink: UseLinkFunction = defaultLink as any; | ||
`; | ||
} |
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.
cb94539
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nuxt-typed-router – ./
nuxt-typed-router-victorgarciaesgi.vercel.app
nuxt-typed-router-git-master-victorgarciaesgi.vercel.app
nuxt-typed-router.vercel.app