How to keep navigation component state in sync with active route? #781
Unanswered
joshua-lehmann
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I am using the antD Menu component for my navigation together with TanStack Router. It works when you click the navigation but if you open the site already with a specific link, it does not work, since the antd menu state is not in sync with the active route. The only solution I found was to use
const currentPath = router.state.matches[router.state.matches.length - 1].pathname;
to set my initial state manually, so that it is in sync. Here you find my simple example on CodeSandbox: https://codesandbox.io/s/antd-menu-tanstack-router-ddns67 you can test the behaviour by going for example to https://ddns67.csb.app/aboutWithout below code, it will not work:
What would be the right approach to use a Menu component that has state together with TanStack Router?
Any suggestions are welcome.
Beta Was this translation helpful? Give feedback.
All reactions