I have an e-commerce site and I migrated the site’s search results pages to use LiveView. Users can paginate the search results, and the liveview uses
push_patch to update the url with a page param like
I want to be able to canonicalize the search results pages such that
fakestore.com/search?page=n… all point to the same canonical url.
I am having a difficult time figuring out how to add a
rel=canonical link to the
head of the page. The LiveView in question inherits from a
root.html layout that stores all of the static metatags, but I can’t simply put the
root.html because that root layout is shared across many other pages, and I only want the
rel=canonical to apply to the search results page.
What is the best method for passing information from a LiveView to the layout?
One idea I have is ditching the
live "path" LiveView call in the router and instead use regular controllers/templates. Then, in the controller, I would be able to pass some information about
rel=canonical to the
conn, and pull that information off of the
conn in the root layout. Then I could use
live_render to render the liveview from within the controller. However, I would really prefer to avoid making changes like these just for this use case.
Thanks for the help!