gpt4 book ai didi

javascript - url 中的双正斜杠会破坏路由器

转载 作者:行者123 更新时间:2023-11-29 23:54:33 24 4
gpt4 key购买 nike

这是我的 React 路由器:

function redirect(nextState, replaceState) {
replaceState({ nextPathName: nextState.location.pathname }, '/')
}

const routes = (
<Route component={App}>
<Route path="/" component={Lead}/>
<Route path="*" onEnter={redirect}/>
</Route>
);

export default routes;

除了'/'之外的每条路由都被重定向到'/'

问题是:如果用户输入 mywebsite.com//服务器将无法提供静态资源,网站将出现没有 JS 和 CSS 的情况

如何解决?

最佳答案

将此添加到 <Switch> 的末尾之前 <Route path="*" >

<Redirect from="//*" to="/*" />

关于javascript - url 中的双正斜杠会破坏路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42004519/

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