Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-router: Uncaught ReferenceError: Router is not defined

I'm following React Router Guide but I'm not even getting to make the simplest example to work. It says Uncaught ReferenceError: Router is not defined.

I'm including these 3 JavaScript files through cdnjs:

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/0.11.6/react-router.js"></script>

And the script the triggers the exception is this:

<script type="text/jsx">
    Router.run(routes, function (Handler, state) {
        React.render(<Handler/>, document.body);
    });
</script>

Am I missing anything? Is Router defined somewhere else? That's weird because it's not stated in the docs.

like image 665
André Pena Avatar asked Jan 18 '15 22:01

André Pena


People also ask

How do you install react router in react?

To install React Router, all you have to do is run npm install react-router-dom@6 in your project terminal and then wait for the installation to complete. If you are using yarn then use this command: yarn add react-router-dom@6 .

How does react router Link work?

React-Router matches the URL and loads up the component for that particular page. Everything happens so fast, and seamlessly, that the user gets a native app-like experience on the browser. There is no flashy blank page in between route transitions.

What is Link from react-router-dom?

A <Link> is an element that lets the user navigate to another page by clicking or tapping on it. In react-router-dom , a <Link> renders an accessible <a> element with a real href that points to the resource it's linking to. This means that things like right-clicking a <Link> work as you'd expect.

What is not found in react-router-Dom?

To solve the error "Module not found: Error: Can't resolve 'react-router-dom'", make sure to install the react-router-dom package by opening your terminal in your project's root directory and running the command npm install react-router-dom and restart your development server.


1 Answers

react-router is defined as ReactRouter on global.

You can access like this.

<script type="text/jsx">
ReactRouter.run(routes, function (Handler, state) {
    React.render(<Handler/>, document.body);
});
</script>
like image 163
koba04 Avatar answered Sep 20 '22 17:09

koba04