ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.4k stars 8.14k forks source link

How do I hide some routes based on API response? #11259

Open mahevstark opened 3 months ago

mahevstark commented 3 months ago

I'm using pro ant design, from "Get Started" button, I have my routes in config/routes.ts and they are only being referenced once in entire project that's config/config.ts, I want to wait for an API response that has list of allowed permissions and then I want to hide/or take out some routes from the list. Like let's say user is not allowed to see "Categories" so the categories menu from routes should be gone. But based on an API response. I tried adding API call in config.ts but awaits are not welcomed there.

MadiAbhilash commented 3 months ago

match the route path with a key kepted in your response, if the response contain the key allow the user to enter the route, if not use a layout which always loads first then keep a useLayoutEffect in it to check this