我在服务器上渲染我的React App,但是我收到此错误TypeError: match is not a function
。我不知道如何解决这个或这个错误意味着什么,因为react-router docs说其他明智的。
var routes = require('./public/src/routes');
var React = require('react');
var renderToString = require('react-dom/server');
var match = require('react-router');
var RouterContext = require('react-router');
app.get('*', (req, res) => {
match(
{ routes, location: req.url },
(err, redirectLocation, renderProps) => {
if (err) {
return res.status(500).send(err.message);
}
let markup;
if(renderProps) {
markup = renderToString(React.createElement(RoutingContext, renderProps));
}
return res.render('index', { markup });
}
)
})
答案 0 :(得分:2)
您将Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy219 cannot be cast to atorrico.cache.CouchbaseCache
at atorrico.cache.configuration.CacheConfiguration$$EnhancerBySpringCGLIB$$dd4e20b8.mainCouchbaseCache(<generated>)
at atorrico.cache.configuration.CacheConfiguration.cacheManager(CacheConfiguration.java:76)
at atorrico.cache.configuration.CacheConfiguration$$EnhancerBySpringCGLIB$$dd4e20b8.CGLIB$cacheManager$0(<generated>)
at atorrico.cache.configuration.CacheConfiguration$$EnhancerBySpringCGLIB$$dd4e20b8$$FastClassBySpringCGLIB$$a8a6f2da.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at atorrico.cache.configuration.CacheConfiguration$$EnhancerBySpringCGLIB$$dd4e20b8.cacheManager(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 67 more
分配给模块match
本身,这不是一个功能,而不是您想要做的事情。 react-router
是模块的部分,而不是模块本身。 match
也是如此。你要做的是:
RouterContext
这需要正确的模块,并将var match = require("react-router").match;
var RouterContext = require("react-router").RouterContext;
正确地分配给模块中的函数。 match
也是如此。或者,使用ES6的新解构分配(相当于):
RouterContext