我想隐藏多个子页面的页脚,但是当我使用
{ 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/