Path segments after interpolation must begin with /, got: "-"

Here’s my link:

<.link navigate={~p"/test/#{job.id}-#{job.slug}"}>

Is there a way to get the URL in the shape I want it?

https://www.example.com/test/123123-some-slug

Edit:

I guess I could not use verified routes for this one route. :thinking:

Could you please provide input data, expected result and actual result?

You can do the string concatenation in the path segment:

~p"/test/#{job.id <> “-“ <> job.slug}"

I would also suggest looking at Phoenix.Param in this case: Phoenix.Param — Phoenix v1.7.10

4 Likes

Yeah I think implementing phoenix param is the way to go, then you can just do #{job} and that will consistently produce what you want without having to remember at every path call site.

2 Likes

Interesting! I’m not sure how I could leverage Params to get the url I’m looking for.

defimpl Phoenix.Param, for: Job do
  def to_param(job) do
    “#{job.id}-#{job.slug}”
  end
end
1 Like