index.html与任何路线都不匹配 - reactjs

时间:2018-04-18 10:14:34

标签: javascript reactjs webpack

我收到此错误消息:

Warning: [react-router] Location "/Users/sm_emamian/Desktop/react%20js/shadyab/dist/index.html" did not match any routes

URL:

http://localhost:3000/

我的webpack.config.js

var path = require('path')
var webpack = require('webpack')
var AssetsPlugin = require('assets-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
//var ExtractTextPlugin = require("extract-text-webpack-plugin");

var DEBUG = !(process.env.NODE_ENV === 'production')

if (DEBUG) {
  require('dotenv').config()
}

var config = {
  devtool: DEBUG ? 'cheap-module-eval-source-map' : false,
  entry: {
    app: ['./app/app'],
    vendor: [
      'react',
      'react-router',
      'redux',
      'react-dom',
      'lodash',
      'bluebird',
      'humps',
      'history'
    ]
  },
  resolve: {
    modules: [ path.join(__dirname, 'app'), 'node_modules' ]
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
  },
  plugins: [
    //new ExtractTextPlugin('styles.css'),
    new HtmlWebpackPlugin(),
    new webpack.EnvironmentPlugin(['NODE_ENV', 'API_BASE_URL']),
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery'
    })
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        include: __dirname
      },
      {
      //  test: /\.css$/,
        test:/\.(s*)css$/,
        use: [
          { loader: "style-loader" },
          { loader: "css-loader" }
        ]
      }
    ]
  }
}


if (DEBUG) {
  config.entry.app.push('webpack-hot-middleware/client?path=/__webpack_hmr')

  config.plugins = config.plugins.concat([
    new webpack.HotModuleReplacementPlugin(),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
      filname: 'vendor.js'
    })
  ])
  config.output.publicPath = '/'
  config.module.rules.unshift({
    test: /\.js$/,
    loader: 'react-hot-loader',
    exclude: /node_modules/,
    include: __dirname
  })
} else {
  config.plugins = config.plugins.concat([
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
      filname: '[name].[chunkhash].js'
    }),
    new webpack.optimize.UglifyJsPlugin(),
  ])
}

module.exports = config

我的routes/index.js

import React from 'react'
import { Provider } from 'react-redux'
import { Router, Route, IndexRoute } from 'react-router'
import configureStore from 'store/configureStore'

import App from 'containers/App'
import Home from 'containers/Home'
import Questions from 'containers/Questions'
import Question from 'containers/Question'
import Detail from 'containers/Detail'
import Cart from 'containers/Cart'
import Login from 'containers/Login'
import Profile from 'containers/Profile'
import Category from 'containers/Category'

export default function(history) {
  return (
    <Router history={history}>
      <Route path="/" component={App}>
        <Route exact path="/offers/:id" component={Detail} />
        <Route path="/cart/cart" component={Cart} />
        <Route path="/login" component={Login} />
        <Route path="/profile/:section" component={Profile} />
        <Route path="/category/:city/:category" component={Category} />
        <IndexRoute component={Home} />
      </Route>
    </Router>
  )
}

我的app.js:

import 'babel-polyfill'

import React from 'react'
import ReactDOM from 'react-dom'
import { browserHistory } from 'react-router'

import configureStore from 'store/configureStore'
import createRoutes from 'routes/index'
import { Provider } from 'react-redux'
import Immutable from 'immutable'
import _ from 'lodash'

let reduxState = {}
if (window.__REDUX_STATE__) {
  try {
    let plain = JSON.parse(unescape(__REDUX_STATE__))
    _.each(plain, (val, key)=> {
      reduxState[key] = Immutable.fromJS(val)
    })
  } catch (e) {
  }
}

const store = configureStore(reduxState)

ReactDOM.render((
  <Provider store={store}>
    { createRoutes(browserHistory) }
  </Provider>
), document.getElementById('root'))

0 个答案:

没有答案