Using router with react by CDN
up vote
3
down vote
favorite
I have this code:
<body>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/4.3.1/react-router.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.js"></script>
<script src="index.js" type="text/babel"></script>
</body>
And javascript:
const Component = React.Component;
const MyApp = () => (
<div>
<Header></Header>
</div>
);
const Header = () => {
return (
<div className="Header">
<img className="banner_image" src="www/banner.jpg"></img>
</div>
);
}
ReactDOM.render(
<MyApp />,
document.getElementById("root")
)
which works pretty well.
But, when I try to add a Router:
const Component = React.Component,
BrowserRouter = ReactRouter.BrowserRouter,
Route = ReactRouter.Route;
export class MyApp extends Component {
render() {
return (
<BrowserRouter>
<div>
<Route exact path="/" component={Header}/>
</div>
</BrowserRouter>
)
}
};
I get this:
Uncaught ReferenceError: exports is not defined
at <anonymous>:3:23
at run (babel.js:61531)
at check (babel.js:61597)
at babel.js:61624
at XMLHttpRequest.xhr.onreadystatechange (babel.js:61549)
I saw it was a problem with Babel, exports, and Typescript but I'm not using this last one anywhere. I really need to use Router but I can't find a solution to this, I also tried to change the versions of my CDN but it didn't work.
javascript reactjs react-router babeljs cdn
add a comment |
up vote
3
down vote
favorite
I have this code:
<body>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/4.3.1/react-router.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.js"></script>
<script src="index.js" type="text/babel"></script>
</body>
And javascript:
const Component = React.Component;
const MyApp = () => (
<div>
<Header></Header>
</div>
);
const Header = () => {
return (
<div className="Header">
<img className="banner_image" src="www/banner.jpg"></img>
</div>
);
}
ReactDOM.render(
<MyApp />,
document.getElementById("root")
)
which works pretty well.
But, when I try to add a Router:
const Component = React.Component,
BrowserRouter = ReactRouter.BrowserRouter,
Route = ReactRouter.Route;
export class MyApp extends Component {
render() {
return (
<BrowserRouter>
<div>
<Route exact path="/" component={Header}/>
</div>
</BrowserRouter>
)
}
};
I get this:
Uncaught ReferenceError: exports is not defined
at <anonymous>:3:23
at run (babel.js:61531)
at check (babel.js:61597)
at babel.js:61624
at XMLHttpRequest.xhr.onreadystatechange (babel.js:61549)
I saw it was a problem with Babel, exports, and Typescript but I'm not using this last one anywhere. I really need to use Router but I can't find a solution to this, I also tried to change the versions of my CDN but it didn't work.
javascript reactjs react-router babeljs cdn
You know you have spelt render as redner right?
– Sparlarva
Nov 17 at 18:22
Thanks, I'm going to edit that, but I tested and it wasn't the issue.
– Quentin Ellak
Nov 17 at 18:24
1
codepen.io/lsmoura/pen/pNPOzp working example which i found
– victor zadorozhnyy
Nov 17 at 18:26
This example works for me, thank you a lot.
– Quentin Ellak
Nov 17 at 18:35
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have this code:
<body>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/4.3.1/react-router.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.js"></script>
<script src="index.js" type="text/babel"></script>
</body>
And javascript:
const Component = React.Component;
const MyApp = () => (
<div>
<Header></Header>
</div>
);
const Header = () => {
return (
<div className="Header">
<img className="banner_image" src="www/banner.jpg"></img>
</div>
);
}
ReactDOM.render(
<MyApp />,
document.getElementById("root")
)
which works pretty well.
But, when I try to add a Router:
const Component = React.Component,
BrowserRouter = ReactRouter.BrowserRouter,
Route = ReactRouter.Route;
export class MyApp extends Component {
render() {
return (
<BrowserRouter>
<div>
<Route exact path="/" component={Header}/>
</div>
</BrowserRouter>
)
}
};
I get this:
Uncaught ReferenceError: exports is not defined
at <anonymous>:3:23
at run (babel.js:61531)
at check (babel.js:61597)
at babel.js:61624
at XMLHttpRequest.xhr.onreadystatechange (babel.js:61549)
I saw it was a problem with Babel, exports, and Typescript but I'm not using this last one anywhere. I really need to use Router but I can't find a solution to this, I also tried to change the versions of my CDN but it didn't work.
javascript reactjs react-router babeljs cdn
I have this code:
<body>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/4.3.1/react-router.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.js"></script>
<script src="index.js" type="text/babel"></script>
</body>
And javascript:
const Component = React.Component;
const MyApp = () => (
<div>
<Header></Header>
</div>
);
const Header = () => {
return (
<div className="Header">
<img className="banner_image" src="www/banner.jpg"></img>
</div>
);
}
ReactDOM.render(
<MyApp />,
document.getElementById("root")
)
which works pretty well.
But, when I try to add a Router:
const Component = React.Component,
BrowserRouter = ReactRouter.BrowserRouter,
Route = ReactRouter.Route;
export class MyApp extends Component {
render() {
return (
<BrowserRouter>
<div>
<Route exact path="/" component={Header}/>
</div>
</BrowserRouter>
)
}
};
I get this:
Uncaught ReferenceError: exports is not defined
at <anonymous>:3:23
at run (babel.js:61531)
at check (babel.js:61597)
at babel.js:61624
at XMLHttpRequest.xhr.onreadystatechange (babel.js:61549)
I saw it was a problem with Babel, exports, and Typescript but I'm not using this last one anywhere. I really need to use Router but I can't find a solution to this, I also tried to change the versions of my CDN but it didn't work.
javascript reactjs react-router babeljs cdn
javascript reactjs react-router babeljs cdn
edited Nov 18 at 0:13
Eugene Mihaylin
9171324
9171324
asked Nov 17 at 18:01
Quentin Ellak
1,6252615
1,6252615
You know you have spelt render as redner right?
– Sparlarva
Nov 17 at 18:22
Thanks, I'm going to edit that, but I tested and it wasn't the issue.
– Quentin Ellak
Nov 17 at 18:24
1
codepen.io/lsmoura/pen/pNPOzp working example which i found
– victor zadorozhnyy
Nov 17 at 18:26
This example works for me, thank you a lot.
– Quentin Ellak
Nov 17 at 18:35
add a comment |
You know you have spelt render as redner right?
– Sparlarva
Nov 17 at 18:22
Thanks, I'm going to edit that, but I tested and it wasn't the issue.
– Quentin Ellak
Nov 17 at 18:24
1
codepen.io/lsmoura/pen/pNPOzp working example which i found
– victor zadorozhnyy
Nov 17 at 18:26
This example works for me, thank you a lot.
– Quentin Ellak
Nov 17 at 18:35
You know you have spelt render as redner right?
– Sparlarva
Nov 17 at 18:22
You know you have spelt render as redner right?
– Sparlarva
Nov 17 at 18:22
Thanks, I'm going to edit that, but I tested and it wasn't the issue.
– Quentin Ellak
Nov 17 at 18:24
Thanks, I'm going to edit that, but I tested and it wasn't the issue.
– Quentin Ellak
Nov 17 at 18:24
1
1
codepen.io/lsmoura/pen/pNPOzp working example which i found
– victor zadorozhnyy
Nov 17 at 18:26
codepen.io/lsmoura/pen/pNPOzp working example which i found
– victor zadorozhnyy
Nov 17 at 18:26
This example works for me, thank you a lot.
– Quentin Ellak
Nov 17 at 18:35
This example works for me, thank you a lot.
– Quentin Ellak
Nov 17 at 18:35
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354021%2fusing-router-with-react-by-cdn%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You know you have spelt render as redner right?
– Sparlarva
Nov 17 at 18:22
Thanks, I'm going to edit that, but I tested and it wasn't the issue.
– Quentin Ellak
Nov 17 at 18:24
1
codepen.io/lsmoura/pen/pNPOzp working example which i found
– victor zadorozhnyy
Nov 17 at 18:26
This example works for me, thank you a lot.
– Quentin Ellak
Nov 17 at 18:35