拒绝特定的浏览器访问我的应用

时间:2019-03-24 19:50:58

标签: html reactjs browser routing routes

寻找一些我可以添加到我的reactjs应用程序中的代码,这些代码将在使用Firefox访问我的应用程序时向用户显示错误。...不支持“浏览器类型”之类的东西。

import './App.css';
import { BrowserRouter as Router, Route, Link, Switch, Redirect } from 'react-router-dom';
import Home from './components/Home';
import Test from './components/Test';
import Test1 from './components/Test1';

class App extends Component {
  render() {
    return (
      <Router>
        <div>
          <Navbar />
          <Switch>
            <Route exact path="/" component={Home} /> <Route exact path="/home" component={Home} /> <Route exact path="/test" component={Test} /> <Route exact path="/test1" component={Test1} />
            <Route component={NoMatch} />
          </Switch>
        </div>
      </Router>
    );
  }
}
export default App;

在线我看到了一些东西,但是我不确定应该在哪里添加到我的app.jsx或index.html或index.jsx……

正在寻找可能为我提供榜样的人

1 个答案:

答案 0 :(得分:0)

尝试

import './App.css';
import { BrowserRouter as Router, Route, Link, Switch, Redirect } from 'react-router-dom';
import Home from './components/Home';
import Test from './components/Test';
import Test1 from './components/Test1';

class App extends Component {

  render() {
  if(navigator.userAgent.indexOf("Firefox") > 0) {
      return <div>Browser not supported </div>
    }
    return (
      <Router>
        <div>
          <Navbar />
          <Switch>
            <Route exact path="/" component={Home} /> <Route exact path="/home" component={Home} /> <Route exact path="/test" component={Test} /> <Route exact path="/test1" component={Test1} />
            <Route component={NoMatch} />
          </Switch>
        </div>
      </Router>
    );
  }
}
export default App;