Loading...
Loading...
Understand and use routing in Umbraco backoffice (foundational concept)
npx skill4agent add umbraco/umbraco-cms-backoffice-skills umbraco-routingumb-router-slot/Umbraco-CMS/src/Umbraco.Web.UI.Client/examples/modal-routed/{
"type": "section",
"alias": "My.Section",
"name": "My Section",
"meta": {
"label": "My Section",
"pathname": "my-section"
}
}/section/my-section{
"type": "dashboard",
"alias": "My.Dashboard",
"name": "My Dashboard",
"meta": {
"label": "Welcome",
"pathname": "welcome-dashboard"
},
"conditions": [
{
"alias": "Umb.Condition.SectionAlias",
"match": "Umb.Section.Content"
}
]
}/section/content/dashboard/welcome-dashboardimport { html, customElement, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import type { UmbRoute } from '@umbraco-cms/backoffice/router';
@customElement('my-routed-element')
export class MyRoutedElement extends UmbLitElement {
@state()
private _routes: UmbRoute[] = [
{
path: 'person/:personId',
component: () => import('./person.element.js'),
setup: (_component, info) => {
console.log('personId:', info.match.params.personId);
},
},
{
path: 'people',
component: () => import('./people.element.js'),
},
{
path: '',
redirectTo: 'people',
},
];
render() {
return html`
<umb-router-slot .routes=${this._routes}></umb-router-slot>
`;
}
}{
path: 'edit/:id',
component: () => import('./edit.element.js'),
setup: (component, info) => {
const id = info.match.params.id;
component.itemId = id;
},
}{
path: '',
redirectTo: 'overview',
}@state()
private _routes: UmbRoute[] = [
{
path: 'overview',
component: () => import('./overview.element.js'),
},
{
path: 'settings',
component: () => import('./settings.element.js'),
},
{
path: 'item/:id',
component: () => import('./item-detail.element.js'),
setup: (component, info) => {
component.itemId = info.match.params.id;
},
},
{
path: '',
redirectTo: 'overview',
},
];render() {
return html`
<nav>
<a href="/section/my-section/overview">Overview</a>
<a href="/section/my-section/settings">Settings</a>
<a href="/section/my-section/item/123">Item 123</a>
</nav>
<umb-router-slot .routes=${this._routes}></umb-router-slot>
`;
}{
"type": "sectionView",
"alias": "My.SectionView",
"name": "My Section View",
"element": "/App_Plugins/MyExtension/section-view.js",
"meta": {
"label": "Organization",
"pathname": "organization",
"icon": "icon-users"
},
"conditions": [
{
"alias": "Umb.Condition.SectionAlias",
"match": "My.Section"
}
]
}/section/my-section/organization// Parent element
@state()
private _routes: UmbRoute[] = [
{
path: 'admin',
component: () => import('./admin-layout.element.js'),
},
{
path: 'users',
component: () => import('./users-layout.element.js'),
},
];
// Admin layout element can have its own nested routes
@state()
private _adminRoutes: UmbRoute[] = [
{
path: 'dashboard',
component: () => import('./admin-dashboard.element.js'),
},
{
path: 'settings',
component: () => import('./admin-settings.element.js'),
},
];{
path: 'edit/:documentId',
component: () => import('./document-editor.element.js'),
setup: (component, info) => {
// Access route parameters
const documentId = info.match.params.documentId;
// Pass to component
component.documentId = documentId;
// Can also access query params, etc.
console.log('Route info:', info);
},
}:paramNameitem/:idredirectTo/section/my-section/section/content/dashboard/welcome/section/my-section/organization/section/my-section/people/person/123