|
2 | 2 |
|
3 | 3 | `this.render()` method is available only [inside hooks](https://github.com/VeliovGroup/flow-router/tree/master/docs#hooks-in-execution-order).
|
4 | 4 |
|
5 |
| - - __Note__: `this.render()` method is available only if application has `templating` and `blaze`, or `blaze-html-templates` packages installed. |
| 5 | +- __Note__: `this.render()` method is available only if application has `templating` and `blaze`, or `blaze-html-templates` packages installed. |
6 | 6 |
|
7 | 7 | #### With Layout
|
| 8 | + |
8 | 9 | `this.render(layout, template [, data, callback])`
|
9 |
| - - `layout` {*String*|*Blaze.Template*} - *Blaze.Template* instance or a name of layout template (*which has* `yield`) |
10 |
| - - `template` {*String*|*Blaze.Template*} - *Blaze.Template* instance or a name of template (*which will be rendered into yield*) |
11 |
| - - `data` {*Object*} - [Optional] Object of data context to use in template. Will be passed to both `layout` and `template` |
12 |
| - - `callback` {*Function*} - [Optional] Callback triggered after template is rendered and placed into DOM. This callback has no context |
| 10 | + |
| 11 | +- `layout` {*String*|*Blaze.Template*} - *Blaze.Template* instance or a name of layout template (*which has* `yield`) |
| 12 | +- `template` {*String*|*Blaze.Template*} - *Blaze.Template* instance or a name of template (*which will be rendered into yield*) |
| 13 | +- `data` {*Object*} - [Optional] Object of data context to use in template. Will be passed to both `layout` and `template` |
| 14 | +- `callback` {*Function*} - [Optional] Callback triggered after template is rendered and placed into DOM. This callback has no context |
13 | 15 |
|
14 | 16 | #### Without Layout
|
| 17 | + |
15 | 18 | `this.render(template [, data, callback])`
|
16 |
| - - `template` {*String*|*Blaze.Template*} - *Blaze.Template* instance or a name of template (*which will be rendered into* `body` *element, or element defined in* `FlowRouter.Renderer.rootElement`) |
17 |
| - - `data` {*Object*} - [Optional] Object of data context to use in template |
18 |
| - - `callback` {*Function*} - [Optional] Callback triggered after template is rendered and placed into DOM. This callback has no context |
| 19 | + |
| 20 | +- `template` {*String*|*Blaze.Template*} - *Blaze.Template* instance or a name of template (*which will be rendered into* `body` *element, or element defined in* `FlowRouter.Renderer.rootElement`) |
| 21 | +- `data` {*Object*} - [Optional] Object of data context to use in template |
| 22 | +- `callback` {*Function*} - [Optional] Callback triggered after template is rendered and placed into DOM. This callback has no context |
| 23 | + |
| 24 | +#### Global catch-all rendering exception: |
| 25 | + |
| 26 | +`FlowRouter.onRenderError = function (error) { /* ... */ };` this callback called with single `error` argument: |
| 27 | + |
| 28 | +- `error` {*Meteor.Error*} — Reason. |
| 29 | + |
| 30 | +Use `FlowRouter.onRenderError` to set global callback to catch errors like `No such layout template` and `No such template`. It's great workaround for dynamically loaded routes and templates, and might be triggered upon broken Internet connection, or when template not loaded for other reason. Here's recommended usage: |
| 31 | + |
| 32 | +```html |
| 33 | +<template name="templatingError"> |
| 34 | + <h1>Oops, something went wrong</h1> |
| 35 | + <p>Network or other error occurred, please try to <a href="#" onclick="window.location.href=window.location.href">reload this page</a> or go back to <a href="/">home page</a>.</p> |
| 36 | +</template> |
| 37 | +``` |
| 38 | + |
| 39 | +```js |
| 40 | +import { FlowRouter } from 'meteor/ostrio:flow-router-extra'; |
| 41 | + |
| 42 | +FlowRouter.onRenderError = function (error) { |
| 43 | + console.error('[onRenderError]', error); |
| 44 | + this.render('templatingError'); |
| 45 | +}; |
| 46 | +``` |
19 | 47 |
|
20 | 48 | #### Features:
|
21 |
| - - Made with animation performance in mind, all DOM interactions are wrapped into `requestAnimationFrame` |
22 |
| - - In-memory rendering (*a.k.a. off-screen rendering, virtual DOM*), disabled by default, can be activated with `FlowRouter.Renderer.inMemoryRendering = true;` |
| 49 | + |
| 50 | +- Made with animation performance in mind, all DOM interactions are wrapped into `requestAnimationFrame` |
| 51 | +- In-memory rendering (*a.k.a. off-screen rendering, virtual DOM*), disabled by default, can be activated with `FlowRouter.Renderer.inMemoryRendering = true;` |
23 | 52 |
|
24 | 53 | #### Settings (*Experimental!*):
|
25 |
| - - Settings below is experimental, targeted to reduce on-screen DOM layout reflow, speed up rendering on slower devices and Phones in first place, by moving DOM computation to off-screen (*a.k.a. In-Memory DOM, Virtual DOM*) |
26 |
| - - `FlowRouter.Renderer.rootElement` {*Function*} - Function which returns root DOM element where layout will be rendered, default: `document.body` |
27 |
| - - `FlowRouter.Renderer.inMemoryRendering` {*Boolean*} - Enable/Disable in-memory rendering, default: `false` |
28 |
| - - `FlowRouter.Renderer.getMemoryElement` {*Function*} - Function which returns default in-memory element, default: `document.createElement('div')`. Use `document.createDocumentFragment()` to avoid extra parent elements |
29 |
| - * The default `document.createElement('div')` will cause extra wrapping `div` element |
30 |
| - * `document.createDocumentFragment()` won't cause extra wrapping `div` element but may lead to exceptions in Blaze engine, depends from your app implementation |
| 54 | + |
| 55 | +- Settings below is experimental, targeted to reduce on-screen DOM layout re-flow, speed up rendering on slower devices and Phones in first place, by moving DOM computation to off-screen (*a.k.a. In-Memory DOM, Virtual DOM*) |
| 56 | +- `FlowRouter.Renderer.rootElement` {*Function*} - Function which returns root DOM element where layout will be rendered, default: `document.body` |
| 57 | +- `FlowRouter.Renderer.inMemoryRendering` {*Boolean*} - Enable/Disable in-memory rendering, default: `false` |
| 58 | +- `FlowRouter.Renderer.getMemoryElement` {*Function*} - Function which returns default in-memory element, default: `document.createElement('div')`. Use `document.createDocumentFragment()` to avoid extra parent elements |
| 59 | + - The default `document.createElement('div')` will cause extra wrapping `div` element |
| 60 | + - `document.createDocumentFragment()` won't cause extra wrapping `div` element but may lead to exceptions in Blaze engine, depends from your app implementation |
31 | 61 |
|
32 | 62 | #### Further reading
|
33 |
| - - [Templating](https://github.com/VeliovGroup/flow-router/blob/master/docs/templating.md) |
34 |
| - - [Templating with "Regions"](https://github.com/VeliovGroup/flow-router/blob/master/docs/templating-with-regions.md) |
35 |
| - - [Templating with Data](https://github.com/VeliovGroup/flow-router/blob/master/docs/templating-with-data.md) |
| 63 | + |
| 64 | +- [Templating](https://github.com/VeliovGroup/flow-router/blob/master/docs/templating.md) |
| 65 | +- [Templating with "Regions"](https://github.com/VeliovGroup/flow-router/blob/master/docs/templating-with-regions.md) |
| 66 | +- [Templating with Data](https://github.com/VeliovGroup/flow-router/blob/master/docs/templating-with-data.md) |
0 commit comments