React Router - 尝试在重定向时加载_ = _

时间:2016-05-18 11:30:50

标签: reactjs react-router

我有一个node.js应用程序,在登录时重定向到http://localhost:8080/。这是使用expressJS完成的,如下所示:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"> <title>Add the Compass widget to a basic 2D map - 4.0</title> <style> html, body, #viewDiv { padding: 0; margin: 0; height: 100%; width: 100%; } </style> <link rel="stylesheet" href="https://js.arcgis.com/4.0/esri/css/main.css"> <script src="https://js.arcgis.com/4.0/"></script> <script> require([ "esri/Map", "esri/views/MapView", "esri/widgets/Compass", "dojo/domReady!" ], function( Map, MapView, Compass ) { var map = new Map({ basemap: "national-geographic" }); var view = new MapView({ container: "viewDiv", scale: 500000, center: [26.26, 39.17], map: map }); /******************************** * Create a compass widget object. *********************************/ var compassWidget = new Compass({ view: view }); // Add the Compass widget to the top left corner of the view view.ui.add(compassWidget, "top-left"); }); </script> </head> <body> <!-- add div for test--> <div style="height:500px;"></div> <div id="viewDiv"></div> </body> </html>

Chrome中的开发者工具显示它正在按预期重定向,因为它执行以下操作:

res.redirect('http://localhost:8080/');

在localhost:8080上有一个react应用程序,它使用react-router来处理路由。其配置如下所示:

Request URL: http://localhost:8080/
Request Method: GET
Status Code: 304 Not Modified
Remote Address: 127.0.0.1:8080

但由于某种原因,应用程序被重定向到const routes = <Route component={AppContainer}> <Route path="/" component={DashboardContainer} /> <Route path="settings" component={SettingsContainer}> <Route path="projects" component={ProjectsContainer}> <Route path="new" component={NewProject} /> </Route> <Route path="views" component={ViewsContainer}> <Route path="new" component={NewView} /> <Route path=":id" component={EditView} /> </Route> <Route path="themes" component={Themes} /> </Route> </Route>; ,这会http://localhost:8080/#/_=_?_k=1yp57h

但是,如果我直接在浏览器中加载http://localhost:8080/http://localhost:8080(跳过重定向部分),则会加载http://localhost:8080/#/?_k=y8p8c9并且应用程序正常运行。

知道发生了什么事吗?

1 个答案:

答案 0 :(得分:1)

解决! node.js上的身份验证过程与Facebook集成在一起。事实证明,在Facebook的回调URL中,它在URL的末尾返回了一个# = ,当我运行res.redirect('http://localhost:8080/');时,它保留了哈希值(没想到)这就是浏览器的工作原理)并重定向到http://localhost:8080/#_=_

要解决这个问题我只是强迫哈希什么都没有: res.redirect('http://localhost:8080/#');

相关问题