javascript - HashRouter,基根“/”
问题描述
我正在使用 HashRouter 路由我的 SPA,问题来自这样一个事实,即我希望在返回主页选项卡时刷新页面,我的 Header 组件中的基本根“/”
<LinkContainer to="/" onClick={window.location.reload}>
<Navbar.Brand>
<img src={logo} alt="" />
</Navbar.Brand>
</LinkContainer>
在我实现 HashRouter 之前,这是可行的,因为我在 home 组件中有一个脚本来呈现一系列文本,该文本并不总是呈现,在 hashrouter 之前,如果您通过导航栏品牌返回主页,则该文本不会呈现,我已修复通过导致页面重新加载来解决该问题。(下面序列文本的代码)
window.onload = () => {
new SequenceRunner({
// Selector targets the html container, in this case a <p> with class (sequence-runner)
selector: ".sequence-runner",
// Content to be displayed.
content: ["Simple", "Reliable", "Affordable"],
// Time
delay: 2500,
}).start();
};
但是现在我开始使用哈希路由器,它以“localhost:3000/#/”为基础,我相信它无法识别链接容器请求。
这也是我的 app.js
<HashRouter>
<main>
<Container fluid>
<Header />
<Route path="/contact" component={ContactUs} />
<Route path="/terms-of-use" component={Terms} />
<Route path="/privacy-policy" component={PrivacyPolicy} />
<Route path="/support" component={Support} />
<Route path="/signup" component={SignUp} />
<Route path="/about" component={About} />
<Route path="/pricing" component={Pricing} />
<Route path="/features" component={TCFeatures} />
<Route path="/" component={Home} exact />
<Footer />
</Container>
</main>
</HashRouter>
解决方案
推荐阅读
- javascript - 如何匹配除 javascript 正则表达式中的特定字符串以外的任何字符集(用于解析 Wikipedia 部分标题的“==”)
- c# - 当 AVCaptureMovieFileOutput 记录视频和音频时 AVPlayerItem Duration 不正确
- python-3.x - 计算从相机到检测到的物体的角度
- android - 根据图像尺寸动态居中搜索栏
- fonts - 如何将 Ttf 或其他字体转换为 .Xnb/XNA Game Studio 字体?
- java - 未解决的参考 由于接收器类型不匹配,以下候选均不适用
- visual-studio-code - 在 vscode 中使用调试器时按 ctrl+c 传递 SIGINT
- reactjs - 使用“valuePropName:'defaultValue'”时动态antd表单初始值设置问题
- javascript - 为什么即使在捕获错误之后 fetch 也会返回?
- node.js - 来自 Node.js 的 Microsoft Dynamics NAV '18 Web 服务的 NTLM 身份验证失败