How to use the omio.renderToString function in omio

To help you get started, we’ve selected a few omio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tencent / omi / packages / omi-ssr / src / server.js View on Github external
//fetch,
      // The twins below are wild, be careful!
      pathname: req.path,
      query: req.query
    };

    const route = await router.resolve(context);

    if (route.redirect) {
      res.redirect(route.status || 302, route.redirect);
      return;
    }

    const data = { ...route };

    const obj = Omi.renderToString(route.component, {}, { data: route.data })


    const scripts = new Set();
    const addChunk = chunk => {
      if (chunks[chunk]) {
        chunks[chunk].forEach(asset => scripts.add(asset));
      } else if (__DEV__) {
        throw new Error(`Chunk with name '${chunk}' cannot be found`);
      }
    };
    addChunk('client');
    if (route.chunk) addChunk(route.chunk);
    if (route.chunks) route.chunks.forEach(addChunk);

    data.scripts = Array.from(scripts);
    data.app = {
github Tencent / omi / packages / omi-ssr-simple / src / index.js View on Github external
app.get('/', function (req, res) {
  const obj = Omi.renderToString()
  res.end(`

  
    <title>Omi SSR</title>
    ${obj.css.join('')}
  
  ${obj.html}
`)
})
github Tencent / omi / packages / omi-ssr / src / server.js View on Github external
if (route.chunks) route.chunks.forEach(addChunk);

    data.scripts = Array.from(scripts);
    data.app = {
      apiUrl: config.api.clientUrl,
    };

    if (route.data) {
      data.scriptData = 'var __data = ' + JSON.stringify(route.data)
    }

    data.children = obj.html
    data.css = obj.css
    //const html = ReactDOM.renderToStaticMarkup();
    //const html = ReactDOM.renderToStaticMarkup(<div>);
    const resutl = Omi.renderToString()
    res.status(route.status || 200);

    res.send(`${resutl.html}`);
  } catch (err) {
    next(err);
  }
});
</div>

omio

Omi for old browsers(IE8+).

MIT
Latest version published 4 years ago

Package Health Score

58 / 100
Full package analysis