ShawnMcCool

ShawnMcCool

Phoenix LiveView and Link Anchors

Hex: 2.0.6
Elixir: 1.15.7
OTP: 25.3.2.7
Phoenix: 1.7.10
Phoenix LiveView: 0.20.1

I’m having difficulties with anchor links in LiveView. Clicking the takes the browser to the tag with the correct ‘id’. But hitting the ‘back’ button does not return the reader to the previous anchor.

I’m generating an article ‘table of contents’ dynamically. I’m doing this for a learner project and I realize that LiveView is probably not the perfect use case for a blog.

An example that works: Introduction - ShawnMc.Cool This is a traditional controller / template.

An example that doesn’t work: Active Record: How We Got Persistence Perfectly Wrong - ShawnMc.Cool

This is a live view component. Click the links below the title (not in the top navigation) and the anchors work. But hit ‘back’ and nothing happens.

I have attempted the following approaches to anchor link generation:

  def render(assigns) do
    ~H"""
    <.link navigate={~p"/#{@article[:slug]}/#article"}>Article</.link>
    <.link navigate={~p"/#{@article[:slug]}/#typical-approach"}>Typical Approach</.link>

    <a href="#article">Article</a>
    <a href="#typical-approach">Typical</a>
    """
  end

Thank you in advance for any help you can provide.

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement