Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass SSR context #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

pass SSR context #25

wants to merge 1 commit into from

Conversation

fabien-h
Copy link

This PR concerns this issue on FlowRouter : kadirahq/flow-router#205

When ReactLayout.render is called asynchronousely, the ssr context is not accessible anymore. This is a double PR (I'ma making the same for DocHead). It just add the context as an optionnal parametter of the render and _addToHead functions.

So in the action hook of the route constructor in flow router, you can now do this :

action( params, queryParams ) {

    let context;
    if ( Meteor.isServer )
        context = FlowRouter.ssrContext.get();

    Meteor.call( 'getAsyncData', ( err, data ) => {

        DocHead.setTitle( data.title, context );

        DocHead.addMeta( {
            name: 'description',
            content: data.description
        }, context );

        ReactLayout.render( ReactLayouts.MainLayout, {
            content: <ReactView.MyView data={ data } />,
        }, context );

    } );

}

There's probably a smarter way, but this one works.

This PR concerns this issue on FlowRouter : kadirahq/flow-router#205

When ReactLayout.render is called asynchronousely, the ssr context is not accessible anymore. This is a double PR (I'ma making the same for DocHead). It just add the context as an optionnal parametter of the render and _addToHead functions.

So in the action hook of the route constructor in flow router, you can now do this :

	action( params, queryParams ) {

		let context;
		if ( Meteor.isServer )
			context = FlowRouter.ssrContext.get();

		Meteor.call( 'getAsyncData', ( err, data ) => {
		
			DocHead.setTitle( data.title, context );
		
			DocHead.addMeta( {
				name: 'description',
				content: data.description
			}, context );
		
			ReactLayout.render( ReactLayouts.MainLayout, {
				content: <ReactView.MyView data={ data } />,
			}, context );
		
		} );

	}

There's probably a smarter way, but this one works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant