0

hey guys having trouble with react-router, i keep getting this unexpected token you may need an appropriate loader to handle this file type on the line with <Router history={browserHistory}>. im not sure what is going on here any help would be appreciated!

thanks

import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Route, browserHistory } from 'react-router'
import Products from './Products'
import Home from './Home'

document.addEventListener('DOMContentLoaded', function() {
 ReactDOM.render(
  <Router history={browserHistory}>
   <Route path="/" component={Home} />
   <Route path="/" component={Products} />
  </Router>, document.getElementById('mount')
 );
});

webpack.config

var path = require('path');

var config = {
  context: path.join(__dirname, 'src/js'),
  entry: [
   './main.js',
  ],
  output: {
   path: path.join(__dirname, 'www'),
   filename: 'bundle.js',
  },
  module: {
   loaders: [
    {
      test: /\.js$/,
      exclude: /node_modules/,
      loaders: ['babel'],
     },
    ],
  },
     resolve: {
       root: [
       path.join(__dirname, 'node_modules'),
     ],
    },
  };
  module.exports = config;

.babelrc

{
 "presets": ["es2015", "react"]
}
3
  • could you share your webpack.config? Commented Mar 11, 2017 at 16:16
  • just added those files @SivadassN Commented Mar 11, 2017 at 18:01
  • @jordan can you try loader: 'babel-loader' Commented Mar 12, 2017 at 2:31

1 Answer 1

1

This isn't a React Router issue but instead is an issue with your JSX transpilation. Check your webpack.config.js file or your .babelrc file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.