routes - 将路由器操作委托(delegate)给其他应用程序中的 Controller

标签 routes elixir phoenix-framework

我有一个 phoenix 伞项目,其中有许多与我的应用程序相关的路由,还有许多与我的应用程序相关的路由。

目前,我绑定(bind)到两个端口(配置了 main_webchild_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/

相关文章:

rust - 使用 Elixir 通过 Ports 与 Rust 对话,我哪里出错了?

webpack - 不死鸟添加 Assets 的最佳方式

html - 没有 Ecto 的 EEX 模板中的寻呼机 - Elixir 和 Phoenix

elixir - 为什么 Phoenix 不使用 Plug 启动服务器?

arrays - 如何在 Ecto 中做 'where model.field contains array'?

ruby-on-rails - destroy_user_session 导致在 Ruby 中使用 Devise 显示操作

ruby-on-rails - 没有路由匹配 [POST] 以进行删除和更新

elixir - Postgres-Phoenix/Elixir安装错误

angularjs - 使用 ngRoute 进行 Angular 路由不适用于某些路由

java - Play Framework - 在 X 秒后进行处理/重定向时呈现 View