<li>
<router-link to="/cant-leave">/cant-leave</router-link>
</li>
+ <li>
+ <router-link :to="{ name: 'docs', params: { id: 'é' } }"
+ >/docs/é</router-link
+ >
+ </li>
</ul>
<!-- <transition
name="fade"
</div>
</template>
-<script>
+<script lang="ts">
import { defineComponent, inject, computed } from 'vue'
import { scrollWaiter } from './scrollWaiter'
+import { routeKey, routerKey } from '../src'
export default defineComponent({
name: 'App',
setup() {
- const router = inject('router')
+ const router = inject(routerKey)!
+ const route = inject(routeKey)!
+ const a = inject('idk')
const state = inject('state')
+
const currentLocation = computed(() => {
- const { matched, ...rest } = router.currentRoute.value
+ const { matched, ...rest } = route.value
return rest
})
}
const nextUserLink = computed(
- () =>
- '/users/' +
- String((Number(router.currentRoute.value.params.id) || 0) + 1)
+ () => '/users/' + String((Number(route.value.params.id) || 0) + 1)
)
- return { currentLocation, nextUserLink, state, flushWaiter, setupWaiter }
+ return {
+ currentLocation,
+ nextUserLink,
+ state,
+ flushWaiter,
+ setupWaiter,
+ router,
+ a,
+ }
},
})
</script>
Ref,
} from 'vue'
import { RouteLocation } from '../types'
+import { routerKey } from '../injectKeys'
interface UseLinkProps {
to: Ref<RouteLocation> | RouteLocation
// TODO: what should be accepted as arguments?
export function useLink(props: UseLinkProps) {
- const router = inject('router')
+ const router = inject(routerKey)!
const route = computed(() =>
router.resolve(isRef(props.to) ? props.to.value : props.to)
Ref,
} from 'vue'
import { RouteRecordNormalized } from '../matcher/types'
+import { routeKey } from '../injectKeys'
// TODO: make it work with no symbols too for IE
export const matchedRouteKey = Symbol() as InjectionKey<
},
setup(props, { attrs }) {
- const route = inject('route')
+ const route = inject(routeKey)!
const depth: number = inject('routerViewDepth', 0)
provide('routerViewDepth', depth + 1)
import { createRouter, Router } from './router'
-import { Ref, InjectionKey } from 'vue'
import createHistory from './history/html5'
import createMemoryHistory from './history/memory'
import createHashHistory from './history/hash'
} from './types'
import { onBeforeRouteLeave } from './navigationGuards'
-declare module 'vue' {
- function inject<T>(key: InjectionKey<T> | string): T | undefined
- function inject<T>(key: InjectionKey<T> | string, defaultValue: T): T
- function inject(key: InjectionKey<any> | string, defaultValue?: unknown): any
- function inject(name: 'router'): Router
- function inject(name: 'route'): Ref<RouteLocationNormalized>
-}
+export { PathParserOptions } from './matcher'
+export { RouteLocationOptions } from './types/index'
+
+// declare module '@vue/runtime-core' {
+// interface Inject {
+// (name: 'router'): Router
+// (name: 'route'): Ref<RouteLocationNormalized>
+// }
+// function inject<T>(key: InjectionKey<T> | string): T | undefined
+// function inject<T>(key: InjectionKey<T> | string, defaultValue: T): T
+// function inject(key: InjectionKey<any> | string, defaultValue?: unknown): any
+// export function inject(name: 'router'): Router
+// export function inject(name: 'route'): Ref<RouteLocationNormalized>
+// }
+
+export * from './injectKeys'
export {
createHistory,
--- /dev/null
+import { InjectionKey, Ref } from 'vue'
+import { Router, RouteLocationNormalized } from '.'
+
+export const routerKey = ('router' as unknown) as InjectionKey<Router>
+export const routeKey = ('route' as unknown) as InjectionKey<
+ Ref<RouteLocationNormalized>
+>
leaveGuards: [],
}
}
+
+export { PathParserOptions }
return
}
- const matched = inject(matchedRouteKey, {}).value
+ // TODO: fix wrong type
+ const matched = inject(matchedRouteKey, {} as any).value
if (!matched) {
__DEV__ &&
return
}
+ // @ts-ignore
matched.leaveGuards.push(leaveGuard.bind(instance.proxy))
}