首页 > 解决方案 > 从反应路由器dom中的基本网址中删除尾随斜杠

问题描述

我有一个使用react-router-dom. 我实施了Browserrouter there.

所有网址都必须看起来像 http://localhost:8080/build/index.html?path=qmrelsr3pk2nnubhmb6iobj6ynr3ahiehuqa4

basename在 BrowserRouter 中是/build/index.html

DOM 中生成的所有链接都具有正确的结构。但是,如果我单击其中一个,它会/在 index.html 后面添加一个尾随。因此,如果没有正确配置的服务器,我将无法刷新页面。

如何防止/添加?

亲切的问候。

标签: reactjsreact-routerreact-router-dom

解决方案


我侵入了history.push这样的:

history.pushState = ((f) => function pushState(){
  arguments[2] = arguments[2].replace('index.html/', 'index.html');
  const ret = f.apply(this, arguments);

  return ret;
})(history.pushState);

我确定这不是最佳做法,但它确实有效。


推荐阅读