Javascript React-React路由器Dom,hashbang路由解决方案

Javascript React-React路由器Dom,hashbang路由解决方案,javascript,reactjs,iis,react-router-dom,Javascript,Reactjs,Iis,React Router Dom,如何使用React路由器dom和hashbang在React中进行路由? 差不多 我觉得很好 在角度路由中,我在Angular/router的RouterModule中使用{useHash:true}来实现这一点 在Vue路由中,我在createRouter中使用Vue router的history:createWebHashHistory()方法来实现这一点 我有没有办法做到这一点 如果不是,请为我推荐一些其他可靠的路由库 如果你想知道我为什么需要它,答案是IIS。而且我不想在IIS上使用

如何使用React路由器dom和hashbang在React中进行路由? 差不多

我觉得很好

在角度路由中,我在
Angular/router
RouterModule
中使用
{useHash:true}
来实现这一点

在Vue路由中,我在
createRouter
中使用
Vue router
history:createWebHashHistory()
方法来实现这一点

我有没有办法做到这一点

如果不是,请为我推荐一些其他可靠的路由库


如果你想知道我为什么需要它,答案是IIS。而且我不想在IIS上使用过于复杂的程序。

使用而不是其他路由器。

使用而不是其他路由器。

您需要使用一个
HashRouter

例如,您可以执行以下操作:

import { HashRouter as Router, Route, Switch } from 'react-router-dom';

const App = () => {
  return (
    <Router>
      <Switch>
        <Route exact path="/foo">
          <Component1/>
        </Route>
        <Route exact path="/bar">
          <Component2/>
        </Route>
      </Switch>
    </Router>);
}
从'react Router dom'导入{HashRouter as Router,Route,Switch};
常量应用=()=>{
返回(
);
}

您需要使用
哈希路由器

例如,您可以执行以下操作:

import { HashRouter as Router, Route, Switch } from 'react-router-dom';

const App = () => {
  return (
    <Router>
      <Switch>
        <Route exact path="/foo">
          <Component1/>
        </Route>
        <Route exact path="/bar">
          <Component2/>
        </Route>
      </Switch>
    </Router>);
}
从'react Router dom'导入{HashRouter as Router,Route,Switch};
常量应用=()=>{
返回(
);
}

谢谢。但是,如何使用props.match、props.location、props.history。。。在路由的页面上?无论我是在开发服务器上还是在服务器上尝试,现在我尝试了“无法读取未定义的属性'url',它都会抛出错误IIS@Dalibor您需要对路由器使用
。这会有帮助:对不起,对不起。。。它很好用。。我用了“this.props.history.push”而不是“props.history.push”,就像我在尝试HashRouter之前使用的那样。它现在运行良好,这与路由器问题无关;我知道我需要在路由页面的组件中使用withRouter,但这是另一个问题。谢谢非常感谢。但是,如何使用props.match、props.location、props.history。。。在路由的页面上?无论我是在开发服务器上还是在服务器上尝试,现在我尝试了“无法读取未定义的属性'url',它都会抛出错误IIS@Dalibor您需要对路由器使用
。这会有帮助:对不起,对不起。。。它很好用。。我用了“this.props.history.push”而不是“props.history.push”,就像我在尝试HashRouter之前使用的那样。它现在运行良好,这与路由器问题无关;我知道我需要在路由页面的组件中使用withRouter,但这是另一个问题。谢谢