Linking pages in Nav bar

I would like to know how can I link(route) to another page from my navbar?

The file below lives in my navingation.html.heex file (my GitHub)

<a href="/delish_foods" class="block mt-4 lg:inline-block lg:mt-0 text-grey-darkest mr-4 no-underline hover:underline">

The above is not correct, because when I click the button nothing happens what is the process to get my routes linked to a button on the navbar?

You need to learn about the link helper…

There is already an example in the root layout.

You can get all your routes with

mix phx.routes

Try to get some examples, it’s not complicate, but knowing REST is helpful.


Okay I cleaned it up a little by following the guide, thank you for that. So now it looks like this

<%= link("Recipes", to: "/delish_foods") %>

Looks a lot more cleaner and readable. But it still doesn’t work. I did notice the terminal execture this everytime I click the link

  Parameters: %{}
  Pipelines: [:browser]
[debug] QUERY OK source="delish_foods" db=1.3ms idle=1251.5ms
SELECT d0."id", d0."date", d0."ingredients", d0."summary", d0."title", d0."inserted_at", d0."updated_at" FROM "delish_foods" AS d0 []

Yes!! I figures it out, the CSS was throwing off the routes, but thanks for the hexdocs that helped me out a lot.

You should not write the url yourself, but use Route.Helpers, as Routes…