Skip to content

Make defining params optional for router.link #508

@JamesLMilner

Description

@JamesLMilner

Enhancement

When you go to use router.link for a route that has an query parameter (path?{someQueryParam}), that parameter must defined for it not to return undefined. This can be problematic in cases where that query parameter is optional, and you do not want to explicitly set it. Making it required can mean you have to give it some placeholder value and remove it at a later point with route.replace, which is an undesireable work around.

There might be some side effects to making it optional that we would need to consider.

Package Version: 6.0.0

Code
In a process:

routerState.currentRoute = 'path';
routerState.currentParams = { query: 'placeholder' };

Then later we have to remove it:

link = link.replace('?query=placeholder', '');

Expected behavior:

Can just set the currentRoute without having to set currentParams

Actual behavior:

Have to set both currentRoute and currentParams, then strip it out. Also potentially have to add checks to where that query paramter is used to make sure it isn't the placeholder value.

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