You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/router-plugin.md
+25-8
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,7 @@ export default defineWidget({
66
66
67
67
We have a `router.{link|redirect|getCurrentRoute}` methods available on the widget now.
68
68
69
-
After that we must initialize universal router with own routes and options in setup phase of creation widget where structure for `routes` and `options` are defined from [universal-router](https://github.com/kriasoft/universal-router/blob/main/docs/api.md)and returns type from `route.action` method is defined by Merkur router plugin. It is a object with `PageView` as main rendered component for defined path and controller life cycle methods **(init, load, activate, deactivate, destroy)** which extend `load`, `mount`, `unmount` methods from `@merkur/plugin-component` and other controller custom methods with logic for defined path.
69
+
After that we must initialize universal router with own routes and options in setup phase of creation widget where structure for `routes` and `options` are defined from [universal-router](https://github.com/kriasoft/universal-router/blob/main/docs/api.md). The `options` are extended by Merkur with optional settings `protocol`and `host` for generating absolute url address from `link` method. Returns type from `route.action` method is defined by Merkur router plugin. It is a object with `PageView` as main rendered component for defined path and controller life cycle methods **(init, load, activate, deactivate, destroy)** which extend `load`, `mount`, `unmount` methods from `@merkur/plugin-component` and other controller custom methods with logic for defined path.
70
70
The `mount` method use under the hood `widget.viewFactory` method to resolving component for render. So we must set View in createViewFactory as route PageView. If you don't have slots you can set `slotFactories` as empty array or set as route slots.
Merkur resolve current route from pathname in `widget.props`. So we must set it in `./server/routes/widget/widgetAPI.js`. Logic for defined `pathname` is on your use case. For example you can read it from `req.query.pathname` and you must update `merkur.config.mjs` file to send `pathname` from playground page to widget API throught `playground.widgetParams` method and of course change `playground.path` for extending playground page to works for more paths than default '/' path.
156
+
Merkur resolve current route from pathname in `widget.props`. So we must set it in `./server/routes/widget/widgetAPI.js`. Logic for defined `pathname` is on your use case. For example you can read it from `req.query.pathname`. The `req.query.*` or `req.body.*` are inputs to your API endpoint widget. You must validate it before you use in `widget.props`.
After that you must update `merkur.config.mjs` file to send `pathname` from playground page to widget API through `playground.widgetParams` method and of course change `playground.path` for extending playground page to works for more paths than default '/' path.
186
+
187
+
```javascript
171
188
// ./merkur.config.mjs
172
189
173
190
/**
@@ -198,7 +215,7 @@ Returned object from `route.action` method for current route.
198
215
- name - route defined name
199
216
- data - route arguments
200
217
201
-
Returns url for route name with filling route pattern with data.
218
+
Returns url for route name with filling route pattern with data. If you define `protocol` and `host` settings in createRouter options then the url address generated from link method will be absolute.
0 commit comments