Skip to content

Instantly share code, notes, and snippets.

@isaksky
Created May 23, 2019 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaksky/ae8680cd924de1bd6c5f78784cac9384 to your computer and use it in GitHub Desktop.
Save isaksky/ae8680cd924de1bd6c5f78784cac9384 to your computer and use it in GitHub Desktop.
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