Skip to content

Commit 590f699

Browse files
committed
docs: add injection order control using meta.afOrder property
1 parent 023425d commit 590f699

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

adminforth/documentation/docs/tutorial/03-Customization/08-pageInjections.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,55 @@ new AdminForth({
556556
557557
If you hide the logo with `showBrandLogoInSidebar: false`, components injected via `sidebarTop` will take the whole line width.
558558
559+
## Injection order
560+
561+
Most of injections accept an array of components. By defult the order of components is the same as in the array. You can use standard array methods e.g. `push`, `unshift`, `splice` to put item in desired place.
562+
563+
However, if you want to control the order of injections dynamically, which is very handly for plugins, you can use `meta.afOrder` property in the injection instantiation. The higher the number, the earlier the component will be rendered. For example
564+
565+
```ts title="/index.ts"
566+
{
567+
...
568+
customization: {
569+
globalInjections: {
570+
userMenu: [
571+
{
572+
file: '@@/CustomUserMenuItem.vue',
573+
meta: { afOrder: 10 }
574+
},
575+
{
576+
file: '@@/AnotherCustomUserMenuItem.vue',
577+
meta: { afOrder: 20 }
578+
},
579+
{
580+
file: '@@/LastCustomUserMenuItem.vue',
581+
meta: { afOrder: 5 }
582+
},
583+
]
584+
}
585+
}
586+
...
587+
}
588+
```
589+
590+
## Order of components inserted by plugins
591+
592+
For plugins, the plugin developers encouraged to use `meta.afOrder` to control the order of injections and allow to pass it from plugin options.
593+
594+
For example "OAuth2 plugin", when registers a login button component for login page injection, uses `meta.afOrder` and sets it equal to 'YYY' passed in plugin options:
595+
596+
```ts title="/index.ts"
597+
// plugin CODE
598+
YYY.push({
599+
file: '@@/..vue',
600+
meta: {
601+
afOrder: this.pluginOptions.YYY || 0
602+
}
603+
})
604+
```
605+
606+
So you can jsut pass `YYY` option to the plugin to control the order of the injection.
607+
559608
## Custom scripts in head
560609
561610
If you want to inject tags in your html head:

0 commit comments

Comments
 (0)