phoenix_localized_routes icon indicating copy to clipboard operation
phoenix_localized_routes copied to clipboard

Thoughts on this working with ~p routes

Open olivermt opened this issue 3 years ago • 9 comments

Hello,

Have you seen Chris' presentation on phoenix 1.7 and verified routes? Do you reckon this lib will be able to work seamlessly with that? Have you given it any thought?

olivermt avatar Sep 25 '22 17:09 olivermt

Sorry for the late reply, did not get a notification. I will get to this soon, as RC1 has just been released today so the verified routes implementation is considered ‘done’.

BartOtten avatar Nov 08 '22 09:11 BartOtten

Released a Release Candidate version you can try: https://elixirforum.com/t/phoenix-localized-routes-localized-multilingual-routes-in-phoenix/48486/22?u=bartotten

Please let me know if it works as expected.

BartOtten avatar Jan 11 '23 09:01 BartOtten

Tremendous! Will try this next week

olivermt avatar Jan 11 '23 13:01 olivermt

Hi @olivermt,

Could you provide me a status report?

BartOtten avatar Jan 23 '23 13:01 BartOtten

I've encountered an issue when trying to use query params:

<.link href={~p"/users/register?#{[foo: "bar"]}"}>Register</.link>


<.link href={~p"/users/register?#{%{foo: "bar"}}"}>Register</.link>
  1. On the locale to which these routes belong, in this case the en locale, there are only compilation warnings: no route path matches that aren't there when switching to the ~o sigil (Phoenix's verified routes sigil basically).

  2. When you're switching to a different locale, there's an error thrown:

<.link href={~p"/users/register?#{[foo: "bar"]}"}>Register</.link>
Protocol.UndefinedError at GET /europe/be/producten
protocol Phoenix.Param not implemented for [foo: "bar"] of type List. This protocol is implemented for the following type(s): Any, Atom, BitString, Float, Integer, Map
<.link href={~p"/users/register?#{%{foo: "bar"}}"}>Register</.link>
ArgumentError at GET /europe/be/producten
maps cannot be converted to_param. A struct was expected, got: %{foo: "bar"}

Hard coding the params works:

<.link href={~p"/users/register?foo=bar"}>Register</.link>

but only on the hard coded locale route. It's not being copied to the other localized routes:

http://localhost:4000/users/register?foo=bar
http://localhost:4000/europe/be/gebruikers/registreren
http://localhost:4000/europe/nl/gebruikers/registreren
http://localhost:4000/gb/users/register

Expected:

http://localhost:4000/users/register?foo=bar
http://localhost:4000/europe/be/gebruikers/registreren?foo=bar
http://localhost:4000/europe/nl/gebruikers/registreren?foo=bar
http://localhost:4000/gb/users/register?foo=bar

Tested on the bo/phx1.7 branch of the example application.

sfusato avatar Apr 24 '23 16:04 sfusato

Hi @sfusato and @olivermt,

The refactoring of Phoenix Localized Routes has lead to a more flexible lib: Routex. Please give it a try as I am eager to get some feedback before I "publish" the lib at Elixir forum.

Migration from Phoenix Localized Routes (PLR) to Routex Although I have not written a migration guide yet, it should be straightforward.

  • A few key names changes and a list of extensions should be added. https://github.com/BartOtten/routex_example/blob/main/lib/example_web/routex_backend.ex
  • The webserver entrypoint should be slightly adapted https://hexdocs.pm/routex/usage.html

Links Hex: https://hex.pm/packages/routex Demo: https://routex.fly.dev/ Full diff adding Routex to the demo app: https://github.com/BartOtten/routex_example/commit/a1ca0d0f1fb411d33a15864cc765dbb39de428da

BartOtten avatar May 01 '23 23:05 BartOtten

@BartOtten Can you make the routex_example repository public?

sfusato avatar May 02 '23 13:05 sfusato

My bad :)

BartOtten avatar May 02 '23 15:05 BartOtten

Thanks. I'm having a compilation error when adding routex to a new project (opened an issue in the project's repository). The other issue is with regards to a route not found in the example app (opened an issue in the routex_example repository).

sfusato avatar May 03 '23 12:05 sfusato