簡體   English   中英

DataCloneError:無法在“歷史”上執行“pushState”

[英]DataCloneError: Failed to execute 'pushState' on 'History'

我是 Reactjs 的新手。我想從用戶輸入日期范圍並將其傳遞到第二頁(搜索)但是我收到錯誤(DataCloneError:無法在“歷史”上執行“pushState”。)當我傳遞狀態 endDate 和startDate。當我傳遞任何示例字符串(示例 - startdate:“sample”)時,它工作正常。 請幫我擺脫這個錯誤。

import React from "react";
import { Link } from "react-router-dom";
import "react-bootstrap";
import { DateRangePicker } from "react-dates";
import "react-dates/initialize";
import "react-dates/lib/css/_datepicker.css";

function Filters() {
  const [dateRange, setdateRange] = React.useState({
    startDate: null,
    endDate: null,
  });
  const [focus, setFocus] = React.useState(null);
  const { startDate, endDate } = dateRange;
  return (<>
          <DateRangePicker
            startDatePlaceholderText="Check-in"
            endDatePlaceholderText="Check-out"
            startDate={startDate}
            endDate={endDate}
            numberOfMonths={1}
            onDatesChange={({ startDate, endDate }) =>
              setdateRange({ startDate, endDate })
            } 
            showClearDates={true}
            focusedInput={focus}
            onFocusChange={(focus) => setFocus(focus)}
            startDateId="startDateMookh"
            endDateId="endDateMookh"
            minimumNights={1}
          />
        
          <Link to={{ pathname: "/search", state: {
                startdate: "startdate",
                enddate: endDate,
                },}}>
            <div className="search">
              <p>Search</p>
            </div>
          </Link>
        </>
  );
}

export default Filters;

這是第二頁(搜索)

import React from "react";
import Hotellist from "./components/hotellist";
import Filters from "./components/filters";
import { useLocation } from "react-router";

function List() {
  const location = useLocation();
  const {startdate, enddate} = location.state;
  console.log(startdate, enddate);
  return (
   <>
    </>
  );
}

我能找到的是 startDate 和 endDate 不僅僅是日期。 他們擁有比這更多的數據。 僅獲取日期或將數據發送到其他頁面使用時刻

import moment from "moment"

Send it like this

startdate: moment(startDate).format("yyyy-MM-dd")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM