LiveView client side redirect

In my app I have a function component that renders the top navigation bar, consisting of a number of buttons.

Is there a way to do a client side redirect using a button? I read Live view client side redirect via a form but it’s a bit dated already.

Wouldn’t it be possible to implement something like

<button phx-click={JS.redirect(~p"/goto")}>Go!</button>

…?

Otherwise I guess I need to make the nav bar a Live component and have it receive the click events, right?

I think the normal way to do this is a good old fashioned <.link that is simply styled to look like a button. This produces a proper <a that will behave more normally than a button.

1 Like