@tanstack/react-router – aria-current=”page” on parent still set on child routes?

I’m using @tanstack/react-router file-based routing. I have links in my __root.tsx element. Let’s say some of these links point to /route1, /route2, /route3.

In my global scss file, I have a line like this, which disables links with property aria-current="page"

[aria-current="page"] {
  pointer-events: none;
  cursor: default;
  text-decoration: none;
}

Whenever I’m on a page of that route, such as /route1, the link is disabled, which is expected behavior. But, when I’m on a child route (route1/$id), the link is still disabled. This makes no sense to me, because I cannot navigate up the /route1 from the child route.

In Chrome’s inspect, the <Link> element looks like this:

<a class="false active" href="/route1" data-status="active" aria-current="page">Route1</a>

and still includes those two properties, even though it’s not on the /route1 route anymore, it’s on a child route. Is this expected behavior? I assumed that aria-current="page" prop would be undefined when it’s on the child route, but it’s not.

Uncommenting the scss block above fixed it, but I would still like to have any a elements with aria-current="page" property have that behavior.

Is there any way to fix this and also keep the scss block?

As mentioned above, I was expecting aria-current="page" to be removed from the /route1 link once I routed to a child page, but it’s only undefined on neighbor routes, not child routes.

New contributor

Michael Hsu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

In your case, the parent route (/route1) is still considered active when you are on a child route (/route1/$id), which is why aria-current=”page” is still applied to the parent . This is expected in some routing libraries, as they consider the parent route to be active when any of its children are active.

Here, modify your routing logic so that aria-current=”page” is applied only when the link matches the route exactly (not when it’s on a child route). Some routers (including TanStack/React Router) offer ways to differentiate between an exact route match and a broader match.

You can manually check if the current route is an exact match to disable the link. Here’s a general approach using the useMatch hook from @tanstack/react-router.

 import { Link, useMatch } from '@tanstack/react-router';

const Navbar = () => {
  const isExactRoute1 = useMatch({
    path: '/route1',
    exact: true, // Only match /route1, not /route1/* (children)
  });

  return (
    <nav>
      <Link
        to="/route1"
        aria-current={isExactRoute1 ? 'page' : undefined}
      >
        Route1
      </Link>
      <Link
        to="/route2"
        aria-current={/* Similar logic for other routes */}
      >
        Route2
      </Link>
    </nav>
  );
};

In this case, the aria-current=”page” attribute is only applied if you’re on /route1 exactly, and not on any child routes like /route1/$id.

for learning more about routing concepts in tanstack, official documentation.

https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

@tanstack/react-router – aria-current=”page” on parent still set on child routes?

I’m using @tanstack/react-router file-based routing. I have links in my __root.tsx element. Let’s say some of these links point to /route1, /route2, /route3.

In my global scss file, I have a line like this, which disables links with property aria-current="page"

[aria-current="page"] {
  pointer-events: none;
  cursor: default;
  text-decoration: none;
}

Whenever I’m on a page of that route, such as /route1, the link is disabled, which is expected behavior. But, when I’m on a child route (route1/$id), the link is still disabled. This makes no sense to me, because I cannot navigate up the /route1 from the child route.

In Chrome’s inspect, the <Link> element looks like this:

<a class="false active" href="/route1" data-status="active" aria-current="page">Route1</a>

and still includes those two properties, even though it’s not on the /route1 route anymore, it’s on a child route. Is this expected behavior? I assumed that aria-current="page" prop would be undefined when it’s on the child route, but it’s not.

Uncommenting the scss block above fixed it, but I would still like to have any a elements with aria-current="page" property have that behavior.

Is there any way to fix this and also keep the scss block?

As mentioned above, I was expecting aria-current="page" to be removed from the /route1 link once I routed to a child page, but it’s only undefined on neighbor routes, not child routes.

New contributor

Michael Hsu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

In your case, the parent route (/route1) is still considered active when you are on a child route (/route1/$id), which is why aria-current=”page” is still applied to the parent . This is expected in some routing libraries, as they consider the parent route to be active when any of its children are active.

Here, modify your routing logic so that aria-current=”page” is applied only when the link matches the route exactly (not when it’s on a child route). Some routers (including TanStack/React Router) offer ways to differentiate between an exact route match and a broader match.

You can manually check if the current route is an exact match to disable the link. Here’s a general approach using the useMatch hook from @tanstack/react-router.

 import { Link, useMatch } from '@tanstack/react-router';

const Navbar = () => {
  const isExactRoute1 = useMatch({
    path: '/route1',
    exact: true, // Only match /route1, not /route1/* (children)
  });

  return (
    <nav>
      <Link
        to="/route1"
        aria-current={isExactRoute1 ? 'page' : undefined}
      >
        Route1
      </Link>
      <Link
        to="/route2"
        aria-current={/* Similar logic for other routes */}
      >
        Route2
      </Link>
    </nav>
  );
};

In this case, the aria-current=”page” attribute is only applied if you’re on /route1 exactly, and not on any child routes like /route1/$id.

for learning more about routing concepts in tanstack, official documentation.

https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật