React: Getting absolute URLs with <StaticRouter /> and <Link to="/path/to/page" />

Viewed 141

I'm trying to turn render some HTML for an email using ReactDOMServer.renderToString and for the life of me I can't figure out how to get the paths in a <Link /> to resolve to absolute URLs.

const html = ReactDOMServer.renderToString(
    <StaticRouter location="http://www.test.com" context={context}>
      <Provider store={store}>{content}</Provider>
    </StaticRouter>,
  );

I would assume that if in my <App> I had a <Link to="/path/xyz" /> that that would result in: <a href="http://www.test.com/path/xy">, but it's not.

Thoughts?

1 Answers

Why don't you just use a normal <a href=""> ? Links are meant for internal navigation. Check this and this.

Related