coen.bakker
I have a live session called :home that consists of four LiveViews. From the LiveViews of this live session the user can navigate to a set of ‘secondary’ pages (LiveViews and regular views). Whenever a user does so, this ‘secondary’ page should show a back button that returns the user to the LiveView that they navigated from. If the user loads a ‘secondary’ page directly from the browser’s location bar, the back button is still visible and returns the user to one of the :home LiveViews by default.
I went into this problem thinking I would build it quickly, but cannot seem to find an elegant way to solve it. I can compare the navigation history (History API) with the URL’s of the :home live session, but I wanted to try to store the URL of the LiveView before redirecting the user to the requested page. Because the user is redirected from a LiveView, rather than a regular view, I fail to see how I can add the URL to the session data of the redirected-to page. There is no redirect(socket, to: "/path", session: %{return_to: "/path"}).
Edit:
So my question is: how can I pass data from a LiveView to a navigated-to LiveView/regular page?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
RudManusachi
First thing comes to my mind is to pass “return_to” as a query parameter and have a plug that would read that param and put the value into an “assign” for
conn(for “dead” views). And attach anon_mounthook that does the same but for live_sessions.ericmason
This has the benefit of the button going to the right place when the user has multiple tabs open on your app, which is not the case if you store the path in the session.
coen.bakker
Oh yes. Makes total sense. I like the approach.
coen.bakker
Check. I hadn’t realized that issue yet. Ty.
eahanson
Make sure to validate the
return_tovalue to mitigate phishing attacks: Unchecked Redirect | Hacker101Also, you might want to remove it from the URL so that when people bookmark or share the current URL, it doesn’t send them somewhere unexpected after visiting the URL.