Dynamic routes and editable components
- El Editor universal para editar contenido sin encabezado de forma visual.
- El Editor de fragmentos de contenido para la edición de contenido sin encabezado basada en formularios.
In this chapter, we enable two dynamic Adventure Detail routes to support editable components; Bali Surf Camp and Beervana in Portland.
The Adventure Detail SPA route is defined as /adventure/:slug where slug is a unique identifier property on the Adventure Content Fragment.
Map the SPA URLs to AEM Pages
In the previous two chapters, we mapped editable component content from the SPA's Home view to corresponding Remote SPA root page in AEM at /content/wknd-app/us/en/.
Defining mapping for editable components for the SPA's dynamic routes is similar however we must come up 1:1 mapping scheme between instances of the route and AEM pages.
In this tutorial, we take the name of the WKND Adventure Content Fragment, which is the last segment of the path, and map it to a simple path under /content/wknd-app/us/en/adventure.
So, based on this mapping we must create two new AEM pages at:
/content/wknd-app/us/en/home/adventure/bali-surf-camp/content/wknd-app/us/en/home/adventure/beervana-in-portland
Remote SPA mapping
The mapping for requests leaving the Remote SPA are configured via the setupProxy configuration done in Bootstrap the SPA.
SPA Editor mapping
The mapping for SPA requests when the SPA is opened via AEM SPA Editor are configured via Sling Mappings configuration done in Configure AEM.
Create content pages in AEM
First, create the intermediary adventure Page segment:
-
Log in to AEM Author
-
Navigate to Sites > WKND App > us > en > WKND App Home Page
- This AEM page is mapped as the root of the SPA, so this is where we begin building out the AEM page structure for other SPA routes.
-
Tap Create and select Page
-
Select the Remote SPA Page template, and tap Next
-
Fill out the Page Properties
- Title: Adventure
- Name:
adventure- This value defines the AEM page's URL, and therefore must match the SPA' route segment.
-
Tap Done
Then, create the AEM pages that correspond to each of the SPA's URLs that require editable areas.
-
Navigate into the new Adventure page in the Site Admin
-
Tap Create and select Page
-
Select the Remote SPA Page template, and tap Next
-
Fill out the Page Properties
- Title: Bali Surf Camp
- Name:
bali-surf-camp- This value defines the AEM page's URL, and therefore must match the SPA' route's last segment
-
Tap Done
-
Repeat the steps 3-6 to create the Beervana in Portland page, with:
- Title: Beervana in Portland
- Name:
beervana-in-portland- This value defines the AEM page's URL, and therefore must match the SPA' route's last segment
These two AEM pages hold the respective-authored content for their matching SPA routes. If other SPA routes require authoring, new AEM Pages must be created at their SPA's URL under the Remote SPA page's root page (/content/wknd-app/us/en/home) in AEM.
Update the WKND App
Vamos a colocar el componente <ResponsiveGrid...> creado en el último capítulo, en nuestro componente de SPA AdventureDetail, creando un contenedor editable.
Colocar el componente de la SPA de ResponsiveGrid
Al colocar <ResponsiveGrid...> en el componente AdventureDetail, se crea un contenedor editable en esa ruta. El truco se debe a que varias rutas utilizan el componente AdventureDetail para representarse, debemos ajustar dinámicamente el atributo <ResponsiveGrid...>'s pagePath. Se debe derivar pagePath para que apunte a la página de AEM correspondiente, en función de la aventura que muestre la instancia de la ruta.
-
Abrir y editar
react-app-/src/components/AdventureDetail.js -
Importe el componente
ResponsiveGridy colóquelo sobre el componente<h2>Itinerary</h2>. -
Establezca los atributos siguientes en el componente
<ResponsiveGrid...>. Tenga en cuenta que el atributopagePathagrega el elementoslugactual que se asigna a la página de aventura según la asignación definida anteriormente.pagePath = '/content/wknd-app/us/en/home/adventure/${slug}'itemPath = 'root/responsivegrid'
Esto indica al componente
ResponsiveGridque recupere su contenido del recurso de AEM:/content/wknd-app/us/en/home/adventure/${slug}/jcr:content/root/responsivegrid
Actualice AdventureDetail.js con las líneas siguientes:
...
import { ResponsiveGrid } from '@adobe/aem-react-editable-components';
...
function AdventureDetailRender(props) {
...
// Get the slug from the React route parameter, this will be used to specify the AEM Page to store/read editable content from
const { slug } = useParams();
return(
...
// Pass the slug in
function AdventureDetailRender({ title, primaryImage, activity, adventureType, tripLength,
groupSize, difficulty, price, description, itinerary, references, slug }) {
...
return (
...
<ResponsiveGrid
pagePath={`/content/wknd-app/us/en/home/adventure/${slug}`}
itemPath="root/responsivegrid"/>
<h2>Itinerary</h2>
...
)
}
)
}
El archivo AdventureDetail.js debe tener el siguiente aspecto:
Crear el contenedor en AEM
Con <ResponsiveGrid...> en su lugar y su pagePath establecido dinámicamente en función de la aventura que se está representando, intentamos crear contenido en él.
-
Iniciar sesión en AEM Author
-
Vaya a Sitios > Aplicación WKND > us > en
-
Editar la página de inicio de la aplicación WKND
- Vaya a la ruta Bali Surf Camp en el SPA para editarla
-
Seleccione Vista previa en el selector de modo en la parte superior derecha
-
Toca la tarjeta Bali Surf Camp en el SPA para navegar hasta su ruta
-
Seleccione Editar del selector de modo
-
Busque el área editable Contenedor de diseño justo encima del Itinerario
-
Abra la barra lateral del editor de páginas y seleccione la vista Componentes
-
Arrastre algunos de los componentes habilitados al contenedor de diseño
- Imagen
- Texto
- Título
And create some promotional marketing material. It could look something like this:
-
Preview your changes in AEM Page Editor
-
Refresh the WKND App running locally on http://localhost:3000, navigate to the Bali Surf Camp route to see the authored changes!
When navigating to an adventure detail route that does not have a mapped AEM Page, there is no authoring ability on that route instance. To enable authoring on these pages, simply make an AEM Page with the matching name under the Adventure page!
Enhorabuena.
¡Enhorabuena! You've added authoring ability to dynamic routes in the SPA!
- Added the AEM React Editable Component's ResponsiveGrid component to a dynamic route
- Created AEM pages to supporting authoring of two specific routes in the SPA (Bali Surf Camp and Beervana in Portland)
- Authored content on the dynamic Bali Surf Camp route!
You've now completed exploring the first steps of how AEM SPA Editor can be used to add specific editable areas to a Remote SPA!