"version": "0.0.0",
"scripts": {
"dev": "vite",
- "build": "vite build",
+ "build": "vue-tsc --noEmit && vite build",
"preview": "vite preview --port 4173"
},
"dependencies": {
component: Nested,
end: false,
strict: true,
- beforeEnter(to, from, next) {
+ beforeEnter(to) {
if (!removeRoute) {
removeRoute = router.addRoute('dynamic', {
path: 'child',
component: Dynamic,
})
- next(to.fullPath)
- } else next()
+ return to.fullPath
+ }
},
},
{
"extends": "@vue/tsconfig/tsconfig.web.json",
- "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
+ "include": ["env.d.ts", "src/**/*.ts", "src/**/*.vue"],
"exclude": ["**/node_modules", "**/.*/"],
"compilerOptions": {
+ "allowJs": false,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
RouteNamedMapGeneric,
RouteStaticPathMapGeneric,
} from './named'
+import { LiteralUnion } from './utils'
export type Lazy<T> = () => Promise<T>
export type Override<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
RouteMap extends RouteStaticPathMapGeneric = RouteStaticPathMapGeneric
> = RouteStaticPathMapGeneric extends RouteMap
? string
- : {
- [K in keyof RouteMap]: RouteMap[K]['fullPath']
- }[keyof RouteMap]
+ : LiteralUnion<
+ {
+ [K in keyof RouteMap]: RouteMap[K]
+ }[keyof RouteMap],
+ string
+ >
/**
* Route Location that can infer the necessary params based on the name.
> = RouteStaticPathMapGeneric extends RouteMap
? // allows assigning a RouteLocationRaw to RouteLocationPat
RouteQueryAndHash & LocationAsPath & RouteLocationOptions
- : {
- [K in Extract<keyof RouteMap, string>]: RouteQueryAndHash &
- LocationAsPath<RouteMap[K]['path']> &
- RouteLocationOptions
- }[Extract<keyof RouteMap, string>]
+ : RouteQueryAndHash &
+ RouteLocationOptions &
+ LocationAsPath<
+ LiteralUnion<
+ { [K in keyof RouteMap]: RouteMap[K] }[keyof RouteMap],
+ string
+ >
+ >
export interface RouteLocationMatched extends RouteRecordNormalized {
// components cannot be Lazy<RouteComponent>
[N in Name]: {
// name: N
params: ParamsFromPath<_JoinPath<Prefix, Path>>
- // TODO: ParamsRawFromPath
paramsRaw: ParamsRawFromPath<_JoinPath<Prefix, Path>>
path: _JoinPath<Prefix, Path>
}
// END: 1
}
-/**
- * Type that adds valid semi literal paths to still enable autocomplete while allowing proper paths
- */
-type _PathForAutocomplete<P extends string> = P extends `${string}:${string}`
- ? LiteralUnion<P, PathFromParams<P>>
- : P
-
-/**
- * @internal
- */
-export type _PathWithHash<P extends string> = `${P}#${string}`
-
-/**
- * @internal
- */
-export type _PathWithQuery<P extends string> = `${P}?${string}`
-
-/**
- * @internal
- */
-export type _FullPath<P extends string> = LiteralUnion<
- P,
- _PathWithHash<P> | _PathWithQuery<P>
->
-
/**
* @internal
*/
infer Children
>
? {
- // TODO: add | ${string} for params
- // TODO: add extra type to append ? and # variants
- [P in Path as _JoinPath<Prefix, Path>]: {
- path: _PathForAutocomplete<_JoinPath<Prefix, Path>>
- fullPath: _FullPath<_PathForAutocomplete<_JoinPath<Prefix, Path>>>
- }
+ [P in Path as _JoinPath<Prefix, Path>]: _JoinPath<Prefix, Path>
} & (Children extends Readonly<RouteRecordRaw[]> // Recurse children
? RouteStaticPathMap<Children, _JoinPath<Prefix, Path>>
: {
*
* @internal
*/
-export type RouteStaticPathMapGeneric = Record<
- string,
- { path: string; fullPath: string }
->
+export type RouteStaticPathMapGeneric = Record<string, string>
/**
* Relevant information about a named route record to deduce its params.
// paths
r2[method]({ path: '/nested' })
+ r2[method]({ path: '/nested/:a/b' })
+ // with an actual param
r2[method]({ path: '/nested/a/b' })
- // @ts-expect-error
+ // NOTE: we actually accept any string because of perf bottlenecks due to tuples
r2[method]({ path: '' })
- // @ts-expect-error
r2[method]({ path: '/nope' })
- // @ts-expect-error
r2[method]({ path: '/no-name?query' })
- // @ts-expect-error
r2[method]({ path: '/no-name#hash' })
r2[method]('/nested')
r2[method]('/nested/a/b')
- // @ts-expect-error
+
+ // NOTE: same as above
r2[method]('')
- // @ts-expect-error
r2[method]('/nope')
r2[method]('/no-name?query')
r2[method]('/no-name#hash')