javascript - How to preserve last page when using back button with react-router?
问题描述
I’m doing a redirect from within a component’s render like this:
import React, { Component } from "react";
import browserHistory from "react-router/lib/browserHistory";
class LoginRedirectExample extends Component {
constructor(props) {
super(props)
}
redirectToLogin() {
browserHistory.push("/login”);
return null;
}
render () {
return (
<div className={c("container")}>
{
this.props.isLoggedIn ? this.redirectToLogin() : <button>Click Me</button>
}
</div>
)
}
}
Works great - but when if I’m redirected to the login view - I can’t use the browser back button - it doesn’t do anything. How do I handle this redirect and still have the functionality of the back button with react router? I’m using react-router 3 if that makes a difference.
解决方案
推荐阅读
- node.js - 如何在nest.js 中使用全局变量?
- eclipse - 在 http://dl.microsoft.com/eclipse/ 找不到存储库
- azure - 在 Docker 中使用 Selenium 测试运行 Azure 管道
- python - 在 django 中使用块内容时标签有问题
- php - register_activation_hook 不起作用 - Wordpress
- swiftui - 使用 SwiftUI 修复了 iOS 14 小部件中的字体大小
- jquery - 用回车键搜索
- c++ - 为什么 std::set 的构造函数两次比较相同的元素?
- javascript - Nightwatch - 如何在测试文件中指定客户端数量
- distributed-system - 为什么我们需要分区容差 [CAP]