我正在尝试提供一个可运行React SPA的phoenix应用程序,以及以下建议:When accessing front-end SPA-links from browser, back-end fires finding no route
在遵循上述解决方案之前,我已经成功设置了此设置,因此我知道它在过去一直有效。
这里有我路由器上的相关位:
pipeline :browser do
plug(:accepts, ["html"])
end
...
scope "/" do
pipe_through(:browser)
get("/*anything", TexWeb.StaticController, :index)
end
我的第一个客户端路由位于/start
。当我去那里时,发现在日志中收到两个get请求:
Generated tex app
[info] Running TexWeb.Endpoint with Cowboy using http://0.0.0.0:4000
[info] GET /start
[debug] Processing with TexWeb.StaticController.index/2
Parameters: %{"anything" => ["start"]}
Pipelines: [:browser]
[info] Sent 200 in 141µs
[info] GET /static/js/main.8e39f2e0.js
[debug] Processing with TexWeb.StaticController.index/2
Parameters: %{"anything" => ["static", "js", "main.8e39f2e0.js"]}
Pipelines: [:browser]
[info] Sent 200 in 183µs
我已经将完全相同的SPA代码复制到另一个phoenix 1.3实例,并且它成功加载了start
路由。有趣的是,该日志如下所示:
[info] GET /start
[debug] Processing with TexappWeb.StaticController.index/2
Parameters: %{"anything" => ["start"]}
Pipelines: [:browser]
[info] Sent 200 in 17ms
[info] GET /
[debug] Processing with TexappWeb.StaticController.index/2
Parameters: %{"anything" => []}
Pipelines: [:browser]
[info] Sent 200 in 129µs
我很确定这一行:
Parameters: %{"anything" => ["static", "js", "main.8e39f2e0.js"]}
是我遇到问题的原因。
但是我应该从哪里开始调试呢?
答案 0 :(得分:0)
忘记更改endpoint.ex
发件人:
plug(Plug.Static, at: "/", from: :tex, gzip: false, only: ~w(css fonts images js favicon.ico robots.txt))
收件人:
plug(Plug.Static, at: "/", from: :tex, gzip: false)