我有一个 phoenix 伞项目,其中有许多与我的主
应用程序相关的路由,还有许多与我的子
应用程序相关的路由。
目前,我绑定(bind)到两个端口(配置了 main_web
和 child_web
的端口),然后链接到我的 child
内部的路由应用程序引用与我的子端口关联的 url。
我可以只绑定(bind)一个端口并在以下 router.ex
文件中添加一些内容吗:
main_web/router.ex
scope "/" do
pipe_through :browser
get "/", MainWeb.PageController, :index
resources "/user", MainWeb.UserController
# Somehow delegating this to the ChildWeb app would be better
scope "/child", ChildWeb do
get "/", Page.Controller, :index
resources "/other", OtherController
end
end
child_web/router.ex
# if this is configured it would be everything after the /child url
scope "/", ChildWeb do
get "/page1", Page1Controller, :index
end
我完全不确定这是如何编写的,但我觉得这个实现可能存在于某个地方,如果有人可以引用我的示例或上面的 Phoenix 文档,我将不胜感激。
最佳答案
您可能想使用 forward/4
:
forward "/child", ChildWeb.Router
关于routes - 将路由器操作委托(delegate)给其他应用程序中的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48406181/