Skip to content

vaadin-side-nav-item wont add current attributes if application is under contextPath #4589

@LaplusIjns

Description

@LaplusIjns

Description

I’m using Hilla with React.
But the original bug seems to come from this repository.
If the application uses a context path,
server.servlet.context-path=/example
in application.properties

for example /example with subpages /page1 and /page2,

React code like this

  <SideNav onNavigate={({ path }) => navigate(path!)} location={location}>
    {createMenuItems().map(({ to, title, icon }) => (
      <SideNavItem path={to} key={to}>
        {icon ? <Icon src={icon} slot="prefix"></Icon> : <></>}
        {title}
      </SideNavItem>
    ))}
  </SideNav>

then navItem with url /example can correctly add the current attribute and appear highlighted.
However, if navItem with url /example/page1, it should theoretically also have current added, but it doesn’t.

it's seems vaadin-side-nav-item.js __isCurrent methods with matchPaths logic is not work correctly

Expected outcome

If app deploy at /example and have page1
then it should hightlight if im also at /example/page1

Minimal reproducible example

  <SideNav onNavigate={({ path }) => navigate(path!)} location={location}>
    {createMenuItems().map(({ to, title, icon }) => (
      <SideNavItem path={to} key={to}>
        {icon ? <Icon src={icon} slot="prefix"></Icon> : <></>}
        {title}
      </SideNavItem>
    ))}
  </SideNav>

Steps to reproduce

add server.servlet.context-path=/example at application.properties
add page1.tsx ... at views folder
then go to /example/page1

the side nav element with path /example/page1 should hightlight

Environment

Vaadin version(s): 25.0.3
OS: windows11

Browsers

hihtlight if at context path
Image

not hightlight
Image

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    🔖 Normal Priority (P2)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions