gpt4 book ai didi

javascript - 在react js中隐藏多个子页面的页脚

转载 作者:行者123 更新时间:2023-12-03 01:20:27 25 4
gpt4 key购买 nike

我想隐藏多个子页面的页脚,但是当我使用

{ window.location.pathname !== "/subpage1" &&<footer /> }
{ window.location.pathname !== "/subpage2" &&<footer /> }

它不起作用,但仅使用其中之一时它可以工作,如何修复它?

最佳答案

如果你想像你尝试的那样使用它,你可以这样做。 window.location.path 也是同样的想法。将“val”替换为“window.location.path”变量。我想我的评论中有额外的弯曲括号。

https://codesandbox.io/s/64j3y7mlv3

 return (
<div>
<Comp1 />
<Comp2 />
<Comp3 />
{val[0] === 1 || val[1] === 2 ? <Footer /> : null}
</div>
);
};

对于您的情况,它将是:

{ window.location.pathname === "/subpage1" || window.location.pathname === "/subpage2" ? null : <footer /> }

正如我所提到的,我只是向您提供了基本想法。它只是关于条件语句。

关于javascript - 在react js中隐藏多个子页面的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51792270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com