手动交易时,Express ReactJS URL不起作用

时间:2019-07-15 16:09:04

标签: reactjs express webpack react-router

我在我的react-redux应用程序中使用Expressjs。我也在使用react-router。但是在URL的一点上。如果我重新加载页面,我会在控制台中得到Uncaught SyntaxError: Unexpected token <。支持我在这里{{ 1}},如果我按http://localhost:3000/exchange重新加载,那么它可以工作。然后,我通过react-router从上一页转到Ctrl+R,它也可以工作。但是,如果我重新加载此页面(http://localhost:3000/exchange/BTC,USDT ),按http://localhost:3000/exchange/BTC,USDT无效。而且我在控制台Ctrl+R中收到上述错误。

我的文件夹结构在这里:

enter image description here


Express http://localhost:3000/exchange/BTC,USDT在这里

server.js

也是我的webpack配置文件

import express from 'express';
import path from 'path';

import webpack from 'webpack';
import webpackMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import webpackConfig from '../webpack.config.dev.js';

const app = express();
const compiler = webpack(webpackConfig);
app.use(webpackMiddleware(compiler, {
    hot: true,
    publicPath: webpackConfig.output.publicPath,
    noInfo: true
}));
app.use(webpackHotMiddleware(compiler));
app.use(express.static('client'));
app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, '/index.html'));
});
app.listen(3000, 'localhost', function(err) {
  if (err) {
    console.log(err);
    return;
  }

  console.log('Listening at http://localhost:3000');
});

Package.json

import path from 'path';
import webpack from 'webpack';
module.exports = {
    mode: 'development',
    devtool: 'eval',
    entry: [
        'webpack-hot-middleware/client',
        path.join( __dirname, '/client/index.js' )
    ],
    output: {
        path: '/',
        publicPath: '/'
    },
    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ],
    module:{
        rules:[
            {
                test: /\.js$/,
                include: path.join(__dirname, 'client'),
                use: [
                    {
                        loader: 'react-hot-loader/webpack'
                    },
                    {
                        loader: 'babel-loader',
                        options:{
                            presets:[
                                'es2015', 'react'
                            ]
                        }
                    }
                ]
            },
            {
                test: /\.(sass|css)$/,
                include: path.join(__dirname, 'client'),
                use: ['style-loader', 'css-loader', 'sass-loader']
            },
            {
                test: /\.(png|jpe?g|svg|gif)$/,
                include: path.join(__dirname, 'client'),
                use:[
                    {
                        loader: 'file-loader',
                        options:{
                            name: '[path][name].[ext]',
                        }
                    }
                ]
            }
        ]
    }
}

}

0 个答案:

没有答案