Open/scroll page on anchor position with live_redirect

In a way I want my link to look like this:

https://www.myapp.com/order/23#comment-12

So that when I click on a link, the app will navigate to a page with comment 12 in view.

Can this be done with live_redirect?

<%= live_redirect "comment", to: Routes.page_path(@socket, MyApp.Web, order.id) %>

Hi, @StarSailor!
I haven’t tried with live_redirect, but with regular ones just appending anchor should work:

<%= live_redirect "comment", to: Routes.page_path(@socket, MyApp.Web, order.id) <> "#comment-12" %>

1 Like

Hi @RudManusachi

Thank you! This worked perfectly! I didn’t know it was so easy! :smile: