小编yka*_*aru的帖子

React 路由器 URL 参数不起作用

我无法让 React Router 中的 URL 参数功能正常工作,任何见解都会有所帮助!我尝试使用“react-router-dom”而不是“react-router”,但我收到了这个人遇到的错误: https: //github.com/ReactTraining/react-router/issues/1799

当我执行 localhost:8000 时,该应用程序可以正常工作。当我访问 localhost:8000/123 时,浏览器按原样呈现 index.html,没有 任何反应。Express 会干扰 React 吗?在 Express 中,我所拥有的如下:

app.get('*', function response(req, res) {
  res.write(middleware.fileSystem.readFileSync(path.join(__dirname, 'dist/index.html')));
  res.end();
});
Run Code Online (Sandbox Code Playgroud)

这是我的main.js:

import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, browserHistory } from 'react-router';
import Routes from './shared/components/Routes';
const ROOT_ELEMENT = 'app';
ReactDOM.render((
   <Router history={browserHistory}>
   {Routes}
   </Router>
), document.getElementById(ROOT_ELEMENT));
Run Code Online (Sandbox Code Playgroud)

我的routes.js:

import { Route, IndexRoute, Link } from 'react-router';

import App from …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router react-router-v4 react-router-dom

5
推荐指数
1
解决办法
1万
查看次数

Express.js强制HTTPS/SSL重定向错误:重定向太多

所以堆栈是这样的:Express和Angular部署到Heroku.我正在尝试通过使用下面突出显示的代码的简单重定向来强制通过HTTPS提供应用程序.但是,当我在浏览器中打开URL时,出现"重定向太多"的错误.

当我输入http:// [myurl] .com时,我可以看到浏览器中的URL更改为https:// [myurl] .com,但该地址没有显示任何内容.它只是显示"太多重定向".这证明它成功地重定向但我觉得Angular搞砸了它.

当我删除下面的重定向代码并在浏览器中手动访问HTTPS或HTTP地址时,它可以正常工作.

//HTTPS redirect middleware
function ensureSecure(req, res, next) {
    console.log(req.protocol + process.env.PORT + '' + req.hostname + req.url);
    if(req.secure || req.hostname=='localhost'){
        //Secure request, continue to next middleware
        next();
    }else{
        res.redirect('https://' + req.hostname + req.url);
        console.log(req.protocol + process.env.PORT + '' + req.hostname + req.url);
    }
}
//Parse the body of the request as a JSON object, part of the middleware stack (https://www.npmjs.com/package/body-parser#bodyparserjsonoptions)
app.use(bodyParser.json());
//Serve static Angular JS assets from distribution, part …
Run Code Online (Sandbox Code Playgroud)

heroku express angularjs

4
推荐指数
1
解决办法
1552
查看次数