{ path: 'settings', component },
],
},
- ],
+ ] as const,
async scrollBehavior(to, from, savedPosition) {
await scrollWaiter.wait()
if (savedPosition) {
},
})
+declare module '../src' {
+ export interface Config {
+ Router: typeof router
+ }
+}
+
const delay = (t: number) => new Promise(resolve => setTimeout(resolve, t))
// remove trailing slashes
{
- "include": ["*.ts", "api", "../src/global.d.ts", "shim.d.ts"],
+ "include": ["./**/*.ts", "api", "../src/global.d.ts", "shim.d.ts"],
"compilerOptions": {
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
import { RouteRecord } from './matcher/types'
import { NavigationFailure } from './errors'
import { isBrowser, noop } from './utils'
+import { RouterTyped } from './typedRouter'
export interface RouterLinkOptions {
/**
* Route Location the link should navigate to when clicked on.
*/
- to: RouteLocationRaw
+ to: Parameters<RouterTyped['push']>[0]
/**
* Calls `router.replace` instead of `router.push`.
*/
NavigationGuard,
RouteLocationNormalizedLoaded,
} from './types'
-import { Router } from './router'
import { RouterView } from './RouterView'
import { RouterLink } from './RouterLink'
+import { RouterTyped } from './typedRouter'
declare module '@vue/runtime-core' {
export interface ComponentCustomOptions {
/**
* {@link Router} instance used by the application.
*/
- $router: Router
+ $router: RouterTyped
}
export interface GlobalComponents {
import { InjectionKey, ComputedRef, Ref } from 'vue'
import { RouteLocationNormalizedLoaded } from './types'
-import { Router } from './router'
import { RouteRecordNormalized } from './matcher/types'
+import { RouterTyped } from './typedRouter'
/**
* RouteRecord being rendered by the closest ancestor Router View. Used for
*
* @internal
*/
-export const routerKey = Symbol(__DEV__ ? 'router' : '') as InjectionKey<Router>
+export const routerKey = Symbol(
+ __DEV__ ? 'router' : ''
+) as InjectionKey<RouterTyped>
/**
* Allows overriding the current route returned by `useRoute` in tests. rl
}
// this one didn't work 🤔
-// export type _LocationAsRelativeRaw<
+// export type LocationAsRelativeRaw<
// RouteMap extends RouteNamedMapGeneric = RouteNamedMapGeneric
// > = {
// [N in keyof RouteMap]: {
import { inject } from 'vue'
import { routerKey, routeLocationKey } from './injectionSymbols'
-import { Router } from './router'
+import { RouterTyped } from './typedRouter'
import { RouteLocationNormalizedLoaded } from './types'
/**
* Returns the router instance. Equivalent to using `$router` inside
* templates.
*/
-export function useRouter(): Router {
+export function useRouter(): RouterTyped {
return inject(routerKey)!
}
RouterTyped,
RouteLocationRaw,
JoinPath,
+ useRouter,
} from './index'
import { DefineComponent } from 'vue'
r2[method]({ params: { a: 2 } })
r2[method]({ params: {} })
r2[method]({ params: { opt: 'hey' } })
+
+ // routes with no params
+ r2[method]({ name: 'nested' })
+ r2[method]({ name: 'nested', params: {} })
// FIXME: is it possible to support this version
// // @ts-expect-error: does not accept any params
// r2[method]({ name: 'nested', params: { eo: 'true' } })
}
+// still allow generics to be passed for convenience
r2.push({} as unknown as RouteLocationRaw)
r2.replace({} as unknown as RouteLocationRaw)
}
}
-function getTypedRouter(): RouterTyped {
- return {} as any
-}
-
-const typedRouter = getTypedRouter()
+const typedRouter = useRouter()
// this one is true if we comment out the line with Router: typeof r2
// expectType<Router>(typedRouter)
expectType<typeof r2>(typedRouter)