martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
425 stars 24 forks source link

URL, in templates, cannot reference non-handler route definitions #242

Closed igbanam closed 4 months ago

igbanam commented 4 months ago

With this root routes file

Marten.routes.draw do
  path "/nested-app", NestedApp::ROUTES, name: "nested_app"
end

A template file cannot reference this route using {% url "nested_app" %}. However, if it points to a handler, like in the example below

Marten.routes.draw do
  path "/nested-app", NestedApp::ROUTES, name: "nested_app"
  path "/direct-to-handler", DirectHandler, name: "direct"
end

Then {% url "direct" %} properly compiles into "/direct-to-handler".

I expect that with the nested routes, the same behaviour should hold?

ellmetha commented 4 months ago

Hey! 👋

Your nested_app route is an including route and as such it does not map to a concrete handler: only concrete handler routes can be resolved using the url template tag.

I imagine your NestedApp::ROUTES constant contains another route map, so instead of trying to resolve nested_app you should probably try to resolve the route of one of the underlying (namespaced) routes (eg. {% url "nested_app:sub_route" %}).