What's the best way to introduce components that generate their own urls?

I was trying to introduce a live component to more uniformly display a data structure that appears broadly across my app, including interactions, and I bumped into a hitch.

I wanted to have a default behavior for a link in the widget, and I discovered in trying to do so that core_components can’t use the ~p sigil. And the threads I could find for fixing it have advice that’s more appropriate for a custom component not in core_components.

I can just pull this component out to its own file and just load the html helpers there, so if that were the end of the story I would just ‘un-ask the question’ and move on. But working on this component has gotten me thinking about other components I might try to make that could be worth a PR, such as a more intelligent back button component (eg for …/show/… routes, which are currently kind of a pain in the butt)

What would be the right way to introduce a core component that did its own patch or navigate arithmetic?

You just need to do:

use MyAppWeb, :verified_routes

in any modules you want to use ~p in.

4 Likes

Oh. Huh.

Can you do that in core_components or am I looking at an infinite loop?

Should not be an infinite loop, no. All it does is does is configure Phoenix.VerifiedRoutes which is ultimately just an import (via another use).

It works. Thanks!

1 Like

Take a look in lib/my_app_web.ex for def verified_routes so see what it does!