【发布时间】:2017-03-15 22:04:48
【问题描述】:
我无法修复此错误... 我启动服务器,一切正常,因为我刷新了 localhost:3000 然后它告诉我一个错误:
TypeError: (0 , _reactRouter.match) 不是函数
我已经安装了“react-router”:“^4.0.0”
import Express from 'express';
import {RouterContext, match} from 'react-router';
import {renderToString } from 'react-dom/server';
import React from 'react';
import routes from './routes.js'
var app = new Express();
app.set('view engine', 'ejs');
app.set('views',__dirname);
//////////////////////////////////////////////////////////////////////
app.get('*', (req, res) => {
match(
{ routes, location: req.url },
(err, redirectLocation, renderProps) => {
if (err) {
return res.status(500).send(err.message);
}
if (redirectLocation) {
return res.redirect(302, redirectLocation.pathname + redirectLocation.search);
}
var markup;
if (renderProps) {
// if the current route matched we have renderProps
markup = renderToString(<RouterContext {...renderProps}/>);
} else {
// otherwise we can render a 404 page
markup = renderToString(<NotFoundPage/>);
res.status(404);
}
// render the index template with the embedded React markup
return res.render('index', { markup });
}
);
});
//////////////////////////////////////////////////////////////////////////////////
var port = process.env.PORT || 3000;
app.listen(port, ()=>{
console.log('Server is listening on port ' + port );
});
【问题讨论】:
标签: javascript reactjs react-router isomorphic-javascript