kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 193 forks source link

[SSR] Feature Request: Support React Helmet #605

Open jschlieber opened 8 years ago

jschlieber commented 8 years ago

Currently using React Helmet with Flow Router SSR has no effect on the server side rendered document head. Supporting React Helmet as an alternative to Meteor DocHead would be great. What do you think?

rozzzly commented 8 years ago

+1

txs commented 8 years ago

+1

ansonla3 commented 8 years ago

+1

ih-hugh commented 8 years ago

+1

exah commented 8 years ago

For now I'm using this workaround:

const helmetToFlow = () => {
  if (Meteor.isServer) {
    const head = ReactHelmet.rewind();
    const headContent =
      head.title +
      head.base +
      head.meta +
      head.link +
      head.script;

    const context = FlowRouter.ssrContext.get();
    context.addToHead(headContent);
  }
}

And call this function in every route action (after mount), like so:

FlowRouter.route('/', {
  name: 'home',
  action(params, query) {
    const pathname = FlowRouter.getRouteName();

    mount(Root, {
      content: <Home title="Home" location={{pathname, params, query}} />
    });

    helmetToFlow();
  }
});
txs commented 8 years ago

I have a question! What's the mount Root for ?

2016-06-23 1:08 GMT+08:00 John Grishin notifications@github.com:

For now I'm using this workaround:

const helmetToFlow = () => { if (Meteor.isServer) { const head = ReactHelmet.rewind(); const headContent = head.title + head.base + head.meta + head.link + head.script;

const context = FlowRouter.ssrContext.get();
context.addToHead(headContent);

} }

And call this function in every route action (after mount), like so:

FlowRouter.route('/', { name: 'home', action(params, query) { const pathname = FlowRouter.getRouteName();

mount(Root, {
  content: <Home title="Home" location={{pathname, params, query}} />
});

helmetToFlow();

} });

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kadirahq/flow-router/issues/605#issuecomment-227811583, or mute the thread https://github.com/notifications/unsubscribe/AAh1WV9xDdEOzwQeLfDdJWk3s5kwkI81ks5qOWwAgaJpZM4INaKF .

exah commented 8 years ago

@txs https://github.com/kadirahq/react-mounter used to mount react Root component into DOM on client and renders to string on server.