反应路由器问题

时间:2016-10-15 23:09:48

标签: node.js reactjs webpack webpack-dev-server

我想出了如何超越"错误:ENOENT:没有这样的文件或目录,stat' / Users / LonnieMcGill / Desktop / ProjectFolder / React_Projects /public/index.html'在错误(本机)"

我修复了我的服务器,看起来像这样:

server.js

const cors = require('cors');
const express = require('express')
const config = require('./config.js');

const app = module.exports = express();

app.use(express.static(__dirname + './../public'));

app.get('*', function(req, res) {
res.sendFile('index.html', { root: './public'});
})

app.listen(config.port, function() { console.log('Server initiated on     port', config.port); })

并添加了一个config.js文件:

module.exports = {
  port: 3000,
  corsOptions: {
    origin: 'http://localhost:' + this.port
  }
}

webpack.config.js

module.exports = {
entry: {
    main: './public/app/PortfolioApp.jsx'
},

devServer: {
 inline: true
},

output: {
    filename: 'bundle.js',
    path: './public/scripts'
},
devtool: 'sourcemap',
module: {
    loaders: [
        {
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            loader: 'babel'
        },
        {
            test: /\.s?css$/,
            exclude: /node_modules/,
            loaders: ["style", "css", "sass"]
        }
    ]
  }
};

PortfolioApp.jsx

import React from 'react';
import ReactDOM from 'react-dom';
import { render } from 'react-dom'
import { Router, Route, browserHistory, Link} from    'react-router';

 import PortfolioHomePage from './component/HomePage.jsx';
 import About from './component/about/About.jsx';

class PortfolioApp extends React.Component{
constructor(){
    super()
 }

 render() {
   return (
     <Router history={browserHistory}>
       <Route path="/" component={PortfolioHomePage} />
        <Route path="/about" component={About} />
     </Router>
     )
    }
   }

    ReactDOM.render(<PortfolioApp />, document.getElementById('app'));

我的文件结构如下:

enter image description here

0 个答案:

没有答案