Created
May 23, 2019 15:00
-
-
Save isaksky/ae8680cd924de1bd6c5f78784cac9384 to your computer and use it in GitHub Desktop.
Update URL via Liveview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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