expect(resolveRelativePath('/add', '/users/posva')).toBe('/add')
})
+ it('resolves empty path', () => {
+ expect(resolveRelativePath('', '/users/posva')).toBe('/users/posva')
+ expect(resolveRelativePath('', '/users')).toBe('/users')
+ expect(resolveRelativePath('', '/')).toBe('/')
+ })
+
it('warns if from path is not absolute', () => {
resolveRelativePath('path', 'other')
resolveRelativePath('path', './other')
},
],
},
+ { path: '/:pathMatch(.*)', component: components.Home, name: 'catch-all' },
]
async function newRouter(
})
})
+ it('resolves relative locations', async () => {
+ const { router } = await newRouter()
+ await router.push('/users/posva')
+ await router.push('add')
+ expect(router.currentRoute.value.path).toBe('/users/add')
+ await router.push('/users/posva')
+ await router.push('./add')
+ expect(router.currentRoute.value.path).toBe('/users/add')
+ })
+
+ it('resolves parent relative locations', async () => {
+ const { router } = await newRouter()
+ await router.push('/users/posva')
+ await router.push('../add')
+ expect(router.currentRoute.value.path).toBe('/add')
+ await router.push('/users/posva')
+ await router.push('../../../add')
+ expect(router.currentRoute.value.path).toBe('/add')
+ })
+
describe('Warnings', () => {
it.skip('avoid infinite redirection loops', async () => {
const history = createMemoryHistory()
}
// no search and no query
- path = path != null ? path : location
+ path = resolveRelativePath(path != null ? path : location, currentLocation)
// empty path means a relative query or hash `?foo=f`, `#thing`
- if (!path) {
- path = currentLocation + path
- } else if (path[0] !== '/') {
- // relative to current location. Currently we only support simple relative
- // but no `..`, `.`, or complex like `../.././..`. We will always leave the
- // leading slash so we can safely append path
- path = currentLocation.replace(/[^\/]*$/, '') + path
- }
return {
fullPath: path + (searchString && '?') + searchString + hash,
return to
}
+ if (!to) return from
+
const fromSegments = from.split('/')
const toSegments = to.split('/')