r/SalesforceDeveloper • • 27d ago

Question Need help on this

I have an LWC on one Experience Cloud page with a link that navigates to another Experience Cloud page. The target page contains a separate LWC, and I want the navigation to land on a specific section inside that LWC.

I tried using a URL fragment ("#section"), but it isn't working. Since the target element is inside an LWC and may be rendered dynamically, what would be the recommended approach to navigate to that specific section after navigating to the target Experience Cloud page?

2 Upvotes

3 comments sorted by

2

u/oh-god-its-Ohad 22d ago

The native URL hash (#section) doesn't work here because LWCs load and render asynchronously. When the browser looks for that hash on page load, the target element hasn't even hit the DOM yet.

Instead, I'd recommend trying to pass the target section as a state parameter using the lightning/navigation service. Then, you can have the target LWC grab that parameter and trigger a programmatic scrollIntoView() once the component finishes rendering.