Skip to content

Commit 6edba5c

Browse files
committed
fix(link): use replace prop
Close vuejs#702
1 parent 09bbc89 commit 6edba5c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

__tests__/RouterLink.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ async function factory(
369369
options: {} as Partial<RouterOptions>,
370370
resolve: jest.fn(),
371371
push: jest.fn().mockResolvedValue(resolvedLocation),
372+
replace: jest.fn().mockResolvedValue(resolvedLocation),
372373
}
373374
router.resolve.mockReturnValueOnce(resolvedLocation)
374375

@@ -799,6 +800,16 @@ describe('RouterLink', () => {
799800
expect(router.push).toHaveBeenCalledTimes(1)
800801
})
801802

803+
it('calls router.replace when clicked with replace prop', async () => {
804+
const { router, wrapper } = await factory(
805+
START_LOCATION_NORMALIZED,
806+
{ to: locations.basic.string, replace: true },
807+
locations.basic.normalized
808+
)
809+
wrapper.find('a')!.trigger('click')
810+
expect(router.replace).toHaveBeenCalledTimes(1)
811+
})
812+
802813
it('calls router.push with the correct ___location for aliases', async () => {
803814
const { router, wrapper } = await factory(
804815
START_LOCATION_NORMALIZED,

src/RouterLink.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export const RouterLinkImpl = /*#__PURE__*/ defineComponent({
132132
type: [String, Object] as PropType<RouteLocationRaw>,
133133
required: true,
134134
},
135+
replace: Boolean,
135136
activeClass: String,
136137
// inactiveClass: String,
137138
exactActiveClass: String,

0 commit comments

Comments
 (0)