RouteQueryAndHash,
MatcherLocationRaw,
RouteLocationNormalized,
- RouteLocation,
} from '../src/types'
import { createMemoryHistory } from '../src'
import { mount, createMockedRoute } from './mount'
} as RouteRecordNormalized
records.childAlias = { aliasOf: records.child } as RouteRecordNormalized
+type RouteLocationResolved = RouteLocationNormalized & { href: string }
+
const locations: Record<
string,
{
string: string
- normalized: RouteLocationNormalized
+ normalized: RouteLocationResolved
toResolve?: MatcherLocationRaw & Required<RouteQueryAndHash>
}
> = {
string: '/home',
// toResolve: { path: '/home', fullPath: '/home', undefined, query: {}, hash: '' },
normalized: {
+ href: '/home',
fullPath: '/home',
path: '/home',
params: {},
// toResolve: { path: '/home', fullPath: '/home', undefined, query: {}, hash: '' },
normalized: {
fullPath: '/foo',
+ href: '/foo',
path: '/foo',
params: {},
meta: {},
// toResolve: { path: '/home', fullPath: '/home', undefined, query: {}, hash: '' },
normalized: {
fullPath: '/home?foo=a&bar=b',
+ href: '/home?foo=a&bar=b',
path: '/home',
params: {},
meta: {},
string: '/p/1/2',
normalized: {
fullPath: '/p/1/2',
+ href: '/p/1/2',
path: '/p/1/2',
params: { p: ['1', '2'] },
meta: {},
string: '/p/1/2/3',
normalized: {
fullPath: '/p/1/2/3',
+ href: '/p/1/2/3',
path: '/p/1/2/3',
params: { p: ['1', '2', '3'] },
meta: {},
string: '/alias',
normalized: {
fullPath: '/alias',
+ href: '/alias',
path: '/alias',
params: {},
meta: {},
string: '/parent',
normalized: {
fullPath: '/parent',
+ href: '/parent',
path: '/parent',
params: {},
meta: {},
string: '/p',
normalized: {
fullPath: '/p',
+ href: '/p',
path: '/p',
params: {},
meta: {},
string: '/parent/child',
normalized: {
fullPath: '/parent/child',
+ href: '/parent/child',
path: '/parent/child',
params: {},
meta: {},
string: '/absolute-child',
normalized: {
fullPath: '/absolute-child',
+ href: '/absolute-child',
path: '/absolute-child',
params: {},
meta: {},
string: '/p/child',
normalized: {
fullPath: '/p/child',
+ href: '/p/child',
path: '/p/child',
params: {},
meta: {},
string: '/parent/c',
normalized: {
fullPath: '/parent/c',
+ href: '/parent/c',
path: '/parent/c',
params: {},
meta: {},
string: '/p/c',
normalized: {
fullPath: '/p/c',
+ href: '/p/c',
path: '/p/c',
params: {},
meta: {},
string: '/not-found',
normalized: {
fullPath: '/not-found',
+ href: '/not-found',
path: '/not-found',
params: {},
meta: {},
async function factory(
currentLocation: RouteLocationNormalized,
propsData: any,
- resolvedLocation: RouteLocation,
+ resolvedLocation: RouteLocationResolved,
slotTemplate: string = ''
) {
const route = createMockedRoute(currentLocation)
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`RouterLink v-slot provides information on v-slot 1`] = `"<a aria-current=\\"page\\" href=\\"/home\\" class=\\"router-link-active router-link-exact-active\\"><span> route: {\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}]} href: \\"/home\\" isActive: \\"true\\" isExactActive: \\"true\\" </span></a>"`;
+exports[`RouterLink v-slot provides information on v-slot 1`] = `"<a aria-current=\\"page\\" href=\\"/home\\" class=\\"router-link-active router-link-exact-active\\"><span> route: {\\"href\\":\\"/home\\",\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}]} href: \\"/home\\" isActive: \\"true\\" isExactActive: \\"true\\" </span></a>"`;
const currentRoute = inject(routeLocationKey)!
const route = computed(() => router.resolve(unref(props.to)))
- const href = computed(() => router.createHref(route.value))
const activeRecordIndex = computed<number>(() => {
// TODO: handle children with empty path: they should relate to their parent
return {
route,
- href,
+ href: computed(() => route.value.href),
isActive,
isExactActive,
navigate,
hasRoute(name: RouteRecordName): boolean
getRoutes(): RouteRecord[]
- resolve(to: RouteLocationRaw): RouteLocation
- createHref(to: RouteLocation): string
+ resolve(to: RouteLocationRaw): RouteLocation & { href: string }
+
push(to: RouteLocationRaw): Promise<TODO>
replace(to: RouteLocationRaw): Promise<TODO>
window.history.scrollRestoration = 'manual'
}
- function createHref(to: RouteLocation): string {
- return history.base + to.fullPath
- }
-
const encodeParams = applyToParams.bind(null, encodeParam)
const decodeParams = applyToParams.bind(null, decode)
function resolve(
location: RouteLocationRaw,
currentLocation?: RouteLocationNormalizedLoaded
- ): RouteLocation {
+ ): RouteLocation & { href: string } {
// const objectLocation = routerLocationAsObject(location)
currentLocation = currentLocation || currentRoute.value
if (typeof location === 'string') {
)
return {
+ // fullPath: locationNormalized.fullPath,
+ // query: locationNormalized.query,
+ // hash: locationNormalized.hash,
...locationNormalized,
...matchedRoute,
+ // path: matchedRoute.path,
+ // name: matchedRoute.name,
+ // meta: matchedRoute.meta,
+ // matched: matchedRoute.matched,
params: decodeParams(matchedRoute.params),
redirectedFrom: undefined,
+ href: history.base + locationNormalized.fullPath,
}
}
? location.params!
: decodeParams(matchedRoute.params)
+ const fullPath = stringifyURL(stringifyQuery, {
+ ...location,
+ path: matchedRoute.path,
+ })
+
return {
- fullPath: stringifyURL(stringifyQuery, {
- ...location,
- path: matchedRoute.path,
- }),
+ fullPath,
hash: location.hash || '',
query: normalizeQuery(location.query),
...matchedRoute,
redirectedFrom: undefined,
+ href: history.base + fullPath,
}
}
beforeEach: beforeGuards.add,
afterEach: afterGuards.add,
- createHref,
onError: errorHandlers.add,
isReady,