Is there any way to save current url address in live_view?

Hi guys!
Let me explain my problem.

I have 3 pages

Product list page -> Product detail page -> Product edit page.

After editing page, click save then redirect to product detail page to see if editing is done correctly.
Then I want to go back to previous Product list page.
So If I click back button of browser, I was back to Product edit page.
How can I go back to previous list page with history of page?
Is there anyway to save current url(route) in params and pass to next page?

example url looks like this
http://localhost:4000/admin/products/Costco/1?page=1&per_page=20&has_next_page=false

Maybe wrangle your redirection with history replacement.

via Phoenix.LiveView — Phoenix LiveView v0.17.9

{:noreply, push_redirect(socket, to: "/", replace: true)}

Alternatively can pass a query parameter when you do your redirect so the LV knows where to go back to.

1 Like