Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ReactRouter CDN way without npm require?

I am new to React. I am using it by directly adding the react.js and react-dom.js files along with browser.min.js for javascript transformation in to my HTML page for practice. Now, I want to use react-router for which I have added ReactRouter.js script file from here. However, I am not able to find any examples to know how to use it. I have tried the following way and its not working:

  <Router history={history}>
    <Route path="/" component={MainComponent}>
      //<Route path="topics/:id" compponent={Topic} />
    </Route>
  </Router>

  ReactDOM.render(<Router />,  document.getElementById('wrapper'));

Can you please help me how to use Router from ReactRouter.js (CDN way) with an example. Thank you.

like image 659
Madav Avatar asked Feb 08 '23 11:02

Madav


1 Answers

let Router = window.ReactRouter;
let RouteHandler = Router.RouteHandler;
let Route = Router.Route;
let DefaultRoute = Router.DefaultRoute;

Add these codes to the top of yours to get the true reference.

like image 79
nof Avatar answered Feb 10 '23 23:02

nof