Skip to content

Commit c677786

Browse files
authored
Add integrating pages snippets for Angular SSR (BuilderIO#4106)
## Description PR is in response to [this ticket](https://builder-io.atlassian.net/browse/EDU-714?atlOrigin=eyJpIjoiODQ0N2EzNjI5OTI5NGM3ZjgyMGM1ZTg1MWIyZTYwZDQiLCJwIjoiaiJ9). Our [Integrating Pages doc](https://www.builder.io/c/docs/integrating-builder-pages) has code snippets for Angular SSR, but those snippets are not in the repository. This PR adds them to the repository with a single test. --------- Signed-off-by: Wes Reid <[email protected]>
1 parent 54ad33c commit c677786

File tree

6 files changed

+81
-0
lines changed

6 files changed

+81
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { findTextInPage, test } from '../helpers/index.js';
2+
3+
test.describe('Landing Page for Angular', () => {
4+
test.beforeEach(async ({ page, packageName }) => {
5+
test.skip(!['angular-17-ssr'].includes(packageName));
6+
// Navigate to the product editorial page
7+
await page.goto('/landing-page-integrating-pages');
8+
});
9+
10+
test('loads landing-page', async ({ page }) => {
11+
await findTextInPage({ page, text: 'Landing page' });
12+
});
13+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
'@typescript-eslint/consistent-type-imports': 'off',
4+
},
5+
};

packages/sdks/snippets/angular-17-ssr/src/app/app.routes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { CustomChildComponent } from './custom-child/custom-child.component';
77
import { EditableRegionComponent } from './editable-regions/editable-regions.component';
88
import { HeroComponent } from './hero/hero.component';
99
import { HomepageComponent } from './home/homepage.component';
10+
import { LandingPageComponent } from './landing-page/landing-page.component';
11+
import { landingPageResolver } from './landing-page/landing-page.resolver';
1012
import { LivePreviewComponent } from './live-preview/live-preview.component';
1113
import { NavBarComponent } from './nav-bar/nav-bar.component';
1214
import { ProductDetailsComponent } from './product-details/product-details.component';
@@ -18,6 +20,11 @@ export const routes: Routes = [
1820
{ path: 'products/:id', component: ProductEditorialComponent },
1921
{ path: 'product/category/jacket', component: ProductDetailsComponent },
2022
{ path: 'landing-page', component: NavBarComponent },
23+
{
24+
path: 'landing-page-integrating-pages',
25+
component: LandingPageComponent,
26+
resolve: { content: landingPageResolver },
27+
},
2128
{
2229
path: 'custom-child',
2330
component: CustomChildComponent,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- app/landing-page.component.html -->
2+
<ng-container *ngIf="content; else notFound">
3+
<builder-content
4+
[model]="model"
5+
[content]="content"
6+
[apiKey]="apiKey"
7+
></builder-content>
8+
</ng-container>
9+
10+
<ng-template #notFound>
11+
<div>404 - Content not found</div>
12+
</ng-template>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// app/landing-page/landing-page.component.ts
2+
3+
import { CommonModule } from '@angular/common';
4+
import { Component } from '@angular/core';
5+
import { ActivatedRoute } from '@angular/router';
6+
import { Content, type BuilderContent } from '@builder.io/sdk-angular';
7+
8+
@Component({
9+
selector: 'app-landing-page',
10+
standalone: true,
11+
imports: [Content, CommonModule],
12+
templateUrl: './landing-page.component.html',
13+
})
14+
export class LandingPageComponent {
15+
apiKey = 'ee9f13b4981e489a9a1209887695ef2b';
16+
model = 'page';
17+
content: BuilderContent | null = null;
18+
19+
constructor(private activatedRoute: ActivatedRoute) {}
20+
21+
ngOnInit() {
22+
this.activatedRoute.data.subscribe((data: any) => {
23+
this.content = data.content;
24+
});
25+
}
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { ActivatedRouteSnapshot, ResolveFn } from '@angular/router';
2+
import { fetchOneEntry, getBuilderSearchParams } from '@builder.io/sdk-angular';
3+
4+
export const landingPageResolver: ResolveFn<any> = (
5+
route: ActivatedRouteSnapshot
6+
) => {
7+
const urlPath = `/${route.url.join('/')}`;
8+
const searchParams = getBuilderSearchParams(route.queryParams);
9+
10+
return fetchOneEntry({
11+
apiKey: 'ee9f13b4981e489a9a1209887695ef2b',
12+
model: 'page',
13+
userAttributes: {
14+
urlPath,
15+
},
16+
options: searchParams,
17+
});
18+
};

0 commit comments

Comments
 (0)