2017-09-01 16 views
0

Meteorのサーバレンダリングパッケージを使用していますが、TypeErrorを取得しています。Meteor.subscribeは関数ではありません。この出来事または何がここMeteorサーバでMeteorサーバをレンダリングする際のTypeError反応ルータv4で

正確に間違っている理由を把握することは、クライアント上の私のコードです:

import React from 'react'; 
import { Meteor } from 'meteor/meteor'; 
import { render } from 'react-dom'; 
import {RenderRoutes} from '../imports/api/routes.jsx' 
import { onPageLoad } from 'meteor/server-render'; 
import ReactDOM from 'react-dom'; 

import { 
    Router, 
    Route, 
    Link, 
    Switch 
} from 'react-router-dom' 
import createBrowserHistory from 'history/createBrowserHistory' 

const history = createBrowserHistory() 

const Application =() => (
    <Router history={history}> 
     <RenderRoutes/> 
    </Router> 
); 

onPageLoad(()=> { 
    ReactDOM.render(<Application/>, document.getElementById('react-root')); 
}); 

、サーバー上:

onPageLoad((sink) => { 
    const context = {}; 

    const App = props => (
     <StaticRouter location={props.location} context={context}> 
     <RenderRoutes/> 
     </StaticRouter> 
    ); 

    sink.renderIntoElementById('app', renderToString(<App location= 
    {sink.request.url} />)); 
    }); 

私ができました上記を使用して、非常に簡単なアプリケーションを正しく動作させるには、エラーを取り込むサブスクリプションとcreatecontainerがあります。それらを処理する別の方法はありますか?あなたは何が起こっているかを把握することができればそれは素晴らしいことだ

export default createContainer(() => { 
    const handle1 = Meteor.subscribe('categories'); 
    const handle2 = Meteor.subscribe('subcategories'); 
    const handle3 = Meteor.subscribe('products'); 
    const isReady1 = handle1.ready() 
    const isReady2 = handle2.ready() 
    const isReady3 = handle3.ready() 
    return { 
    products: isReady3 ? Products.find({}).fetch() : [], 
    categories: isReady1 ? Categories.find({}).fetch() : [], 
    subcats: isReady2 ? SubCategories.find({}).fetch(): [], 
    }; 
}, B2C); 

または私はすべてのサブスクリプションを削除した後 おかげ

答えて

0

を作ってるんだ何の間違い:ここ

は、私がクライアントに加入しています方法です自動公開を追加するとうまくいきますが、私はすべてのデータをどこにでも公開したくないので、不適切な解決策ではないと感じています。

解決済み: Meteor.isClientブロックにすべてのサブスクリプションを置いていますので、サブスクリプションはサーバー上では実行しないようにしてください。コードがクライアント上に存在し、サーバー側でサーバーレンダリング用に使用されていてもMeteor.isClientブロックは、サーバレンダリングでエラーを引き起こす可能性のあるコードに対して提供する必要があります。

関連する問題