【发布时间】:2020-11-10 15:13:06
【问题描述】:
我想从一个页面重定向到另一个页面并传递道具。但我不希望这些参数在 url 中。
方法:
saveForLater(){
if (typeof window !== "undefined") {
window.location.href = "./DataDisplay/";
}
};
我检查了 urlparams 我们可以在 url 中设置 {"id":content}。但我不希望在 url 中传递数据。
我不能在方法中使用 Link/Route。有什么方法可以做/任何图书馆结帐吗?请建议
代码示例:
import React, { Component } from "react";
class DATAFETCH extends Component {
constructor(props) {
super(props);
this.state = {
Attachments: [],
validated: false,
isDoctor:false,
}
saveForLater(){
if (typeof window !== "undefined") {
window.location.href = "./DataDisplay/";
}
};
render() {
return (
/////// Various Fields
<Button
onClick={() => props.submit()}
>
)}
【问题讨论】:
-
您的应用使用什么导航/路由?
Link或Route是什么,为什么不能使用它们? -
LINK : import { Link } from "react-router-dom"; ROUTE:从“react-router-dom”导入 { Switch, Route, Redirect };这些不能在用户定义的函数/componentDidMount 函数等方法中使用。我们根据不同的场景使用多种类型的路由。喜欢:onclick/onsubmit 将使用 Link 进行方法遍历,使用 window.location.href 进行页面遍历。