Skip to content

Instantly share code, notes, and snippets.

@isaksky

isaksky/Foo.ex

Created May 23, 2019
Embed
What would you like to do?
Update URL via Liveview
# In somethingLive.ex:
def handle_event("some_event", _params, socket) do
assign(socket, :updated_url, Routes.project_path(MyApp.Endpoint, :index))
end
# In template: <%= js_url_update_script(assigns[:updated_url]) %>
# In form_helpers.ex, or similar:
def js_url_update_script(updated_url) do
if updated_url do
content_tag(
:script,
raw("window.history.replaceState(null, null,'#{updated_url}')")
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment