Links are pointing to different paths depending on the router segments

I have a router definition that looks like this:

scope "/page" do
  live "/" FooLive, :index
  live "/:page" FooLive, :index

/ goes to the main page, and /bar goes to a named page /bar. The main page also has a name, but I only know the name after loading.

I want to now add links to different pages and my links look like:
<.link patch={@link}> where link is in the form: bar#subtitle.

If I’m currently on the page “/page/main” then the link will point to: /page/bar#subtitle, but if I’m on /page then the link will point to: /bar#subtitle and I want it to also point to /page/bar#subtitle.

Is the best way to solve this to do a push_patch when I’m on /page? or is there some other solution?

If I’m not mistaken I think you’re looking for the p sigil:

Use of the sigil_p macro allows paths and URLs throughout your application to be compile-time verified against your Phoenix router(s).

That would work if I would switch to absolute urls. Currently I wanted to have relative urls because I don’t care about where the route is hosted in the router exactly.

If I switch to absolute urls I need to keep track of where I’m currently at.