Skip to content

Allow router.replace without triggering scrollBehavior #2072

@Dadibom

Description

@Dadibom

What problem does this feature solve?

Using router.replace to update query parameters. However this triggers scrollBehavior and scrolls to the top. As far as I know, there is no way to distinguish between a push and a replace event.

What does the proposed API look like?

Here are some options:

Could be a simple boolean passed to the scrollBehavior function

scrollBehavior (toRoute, fromRoute, savedPosition, isPush) {

It could be put in the route object to be consistent with this suggestion: #1620

scrollBehavior (toRoute, fromRoute, savedPosition) {
    const isPush = toRoute.navigationType === 'push';

I could also work with the replace function accepting an additional parameter, or having a new signature, that simply updates the url and router.$route without going through guards, scrollbehavior etc. I originally just updated the state manually to circumvent this (using history.replaceState), however that caused some other sneaky bugs since vue-router didn't know about these changes.

router.replace(route, true)
// OR
router.replace(route, { noEvents/silent: true })
// OR
router.silentReplace(route)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions