【问题标题】:Load previous page when clicking back button in browser在浏览器中单击后退按钮时加载上一页
【发布时间】:2021-01-16 08:52:19
【问题描述】:

目标:当我点击浏览器中的后退按钮时,我希望加载上一个页面。

目前,当我单击 ProductDetailsPage.js 文件中的后退按钮时,我的应用会恢复为 localhost:3000 没有正斜杠。

当我点击浏览器中的后退按钮时,如何确保我的应用将加载 localhost:3000/ 前向 /

这里是我点击返回的页面的代码:

const addToBasket = () => {
    // dispatch item into data layer
    dispatch({
      type: "ADD_TO_BASKET",
      item: {
        name: product.name,
        brand: product.brand,
        image: product.image,
        price: product.price,
      },
    });
  };

  return (
    <div>
      <img src={product.image} />
      <h3>{product.brand}</h3>
      <h1>{product.name}</h1>
      <p>${product.price}</p>
      <button onClick={addToBasket}>Add to Cart</button>
    </div>
  );
}

我的应用应该使用以下代码恢复到页面Feed.js:

return (
    <div className="feed">
      <div className="feed__cards">
        {products.map((product) => (
          <ProductCard
            image={product.image}
            brand={product.brand}
            name={product.name}
            price={product.price}
            id={product.id}
          />
        ))}
      </div>
    </div>
  );
}

任何帮助将不胜感激。

【问题讨论】:

    标签: reactjs


    【解决方案1】:

    看起来它现在正在工作。我重置了我的服务器并像魅力一样工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 2011-02-15
      相关资源
      最近更新 更多