Reactjs 反应路由器-尝试在重定向时加载=
我有一个node.js应用程序,它在登录时重定向到。这是使用expressJS完成的,如下所示:Reactjs 反应路由器-尝试在重定向时加载=,reactjs,react-router,Reactjs,React Router,我有一个node.js应用程序,它在登录时重定向到。这是使用expressJS完成的,如下所示: res.redirect('http://localhost:8080/'); Chrome中的开发者工具显示它正在按预期重定向,因为它执行以下操作: Request URL: http://localhost:8080/ Request Method: GET Status Code: 304 Not Modified Remote Address: 127.0.0.1:8080 const r
res.redirect('http://localhost:8080/');代码>
Chrome中的开发者工具显示它正在按预期重定向,因为它执行以下操作:
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>;
在localhost:8080上有一个react应用程序,它使用react路由器来处理路由。其配置如下所示:
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>;
const路由=
;
但由于某些原因,应用程序被重定向到http://localhost:8080/#/_=_?_k=1yp57h
这会给出“警告:[react router]位置”/
“不匹配任何路由”
但是,如果我直接加载或在浏览器中加载(跳过重定向部分),它就会加载,并且应用程序工作正常
知道发生了什么吗?解决了!node.js上的身份验证过程与Facebook集成。事实证明,在Facebook的回调URL中,它在URL的末尾返回一个#=,当我运行
res.redirect('http://localhost:8080/');代码>它保留了散列(不认为浏览器应该这样工作)并重定向到http://localhost:8080/#_=_
为了解决这个问题,我只是强制哈希为nothing:
res.redirect('http://localhost:8080/#');代码>