Skip to content

Commit

Permalink
fix(link): use replace prop
Browse files Browse the repository at this point in the history
Close #702
  • Loading branch information
posva committed Jan 9, 2021
1 parent 09bbc89 commit 6edba5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions __tests__/RouterLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ async function factory(
options: {} as Partial<RouterOptions>,
resolve: jest.fn(),
push: jest.fn().mockResolvedValue(resolvedLocation),
replace: jest.fn().mockResolvedValue(resolvedLocation),
}
router.resolve.mockReturnValueOnce(resolvedLocation)

Expand Down Expand Up @@ -799,6 +800,16 @@ describe('RouterLink', () => {
expect(router.push).toHaveBeenCalledTimes(1)
})

it('calls router.replace when clicked with replace prop', async () => {
const { router, wrapper } = await factory(
START_LOCATION_NORMALIZED,
{ to: locations.basic.string, replace: true },
locations.basic.normalized
)
wrapper.find('a')!.trigger('click')
expect(router.replace).toHaveBeenCalledTimes(1)
})

it('calls router.push with the correct location for aliases', async () => {
const { router, wrapper } = await factory(
START_LOCATION_NORMALIZED,
Expand Down
1 change: 1 addition & 0 deletions src/RouterLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const RouterLinkImpl = /*#__PURE__*/ defineComponent({
type: [String, Object] as PropType<RouteLocationRaw>,
required: true,
},
replace: Boolean,
activeClass: String,
// inactiveClass: String,
exactActiveClass: String,
Expand Down

0 comments on commit 6edba5c

Please sign in to comment.