Skip to content

[Bug] Active sidebar function suggestion #133

@lim1017

Description

@lim1017

Version

"@material-ui/core": "4.11.0",

Reproduction link

https://jsfiddle.net/ not needed

Operating System

linux

Device

laptop

Browser & Version

chrome

Steps to reproduce

Creating a sidebar route
Create a sidebar route named /companyprofile
and have another route to a different page /company. (not intended to be navigated to by sidebar)

What is expected?

going to /company should not highlight the /companyprofile in the sidebar

What is actually happening?

going to /company would result in the sidebar behind "active". even though the sidebar route is /companyprofile.

I can see other bugs occuring with the sidebar routes when they have similar names as well, although I did not personally run to them.


Solution

In the sidebar, you have the following function

function activeRoute(routeName) {
return window.location.href.indexOf(routeName) > -1 ? true : false;
}

replace with
return window.location.href.endsWith(routeName) ? true : false;

I think this is less likely to cause the above or any error as it is more precise?

Additional comments

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions