Skip to content

Instantly share code, notes, and snippets.

@isaksky
Created May 23, 2019 15:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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