ryanflorence / react-router-relative-links

MIT License
78 stars 10 forks source link

usage with createElement #1

Open tdfairbrother opened 8 years ago

tdfairbrother commented 8 years ago

Can you please give me an example of how to use the render method with createElement?

I would really like to use relative links but as soon as I drop in the render method on the Router, it doesn't run createElement.

const renderWithMiddleware = applyRouterMiddleware(
    useRelativeLinks()
  );

<Router
        history={history}
        createElement={createElement}
        render={renderWithMiddleware}>

Kind Regards, Tim

tdfairbrother commented 8 years ago

I think I worked it out, does this look correct?

  const createElement = () => {
    return {
      renderContainer: (Component, props) => {
        if (Component.populateStore) {
          Component.populateStore(store, props);
        }
        return React.createElement(Component, props);
      }
    };
  };

  const renderWithMiddleware = applyRouterMiddleware(
    useRelativeLinks(),
    createElement()
  );

Cheers