相关疑难解决方法(0)

如何在Nginx中将所有Angular请求重定向到index.html

我已经创建了一个简单的Nginx配置文件来为Angular服务器,如下所示:

server {
  listen 80;
  listen [::]:80;

  root /path/to/apps/myapp/current/dist;
  access_log /path/to/apps/myapp/current/log/nginx.access.log;
  error_log /path/to/apps/myapp/current/log/nginx.error.log info;

  index index.html;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location / {
    try_files $uri $uri/ =404;
  }
}
Run Code Online (Sandbox Code Playgroud)

所有工作都按预期正常.因为我正在使用Angular UI路由器,所以我想转发所有页面,index.html以便Angular接管(因此请求example.com/users/new将由Nginx重定向index.html,以便Angular UI处理它)用于页面重新加载,链接等.

我怎样才能做到这一点?

我一直在玩这样的选项:

server {
    #implemented by default, change if you need different ip or port
    #listen *:80 | *:8000;
    server_name test.com;
    return 301 $scheme://www.test.com$request_uri;
}
Run Code Online (Sandbox Code Playgroud)

答案所述.但根据所有要求,我无法做任何类似工作.

建议将不胜感激.

javascript nginx angularjs

12
推荐指数
2
解决办法
7479
查看次数

如何使用react-router重新加载页面?

我可以在这个文件(https://github.com/ReactTraining/react-router/blob/v0.13.3/modules/createRouter.js)中看到有一个刷新功能,但我不知道如何调用它.我对react-router很新,我只是用它来使用hashHistory在一些页面之间移动几次.

现在我正在尝试使用它,以便在安装失败时,用户可以通过刷新安装发生的页面(用户当前所在的页面)来选择"重试"我计划执行的选项.任何帮助,将不胜感激.

这是一个在电子上运行的节点应用程序,而不是Web应用程序.

javascript reactjs react-router electron

10
推荐指数
11
解决办法
3万
查看次数

标签 统计

javascript ×2

angularjs ×1

electron ×1

nginx ×1

react-router ×1

reactjs ×1