Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce file-based @analogjs/router library #101

Merged
merged 24 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4191ef3
feat: introduce router package
brandonroberts Oct 4, 2022
9432fcb
feat: add file-based routing functionality
brandonroberts Oct 7, 2022
e481e80
chore: update example app to use @analogjs/router package
brandonroberts Oct 10, 2022
78cce20
refactor: move src/routes to src/app/routes
brandonroberts Oct 10, 2022
cbf9f57
chore: remove console.log
brandonroberts Oct 10, 2022
47f29a5
chore: clean up example app
brandonroberts Oct 10, 2022
5622489
chore: remove styles
brandonroberts Oct 11, 2022
5cabb59
chore: disable e2e test
brandonroberts Oct 11, 2022
0badf34
chore: optimize deps
brandonroberts Oct 11, 2022
be06e8f
chore: switch to standalone imports in favor of modules
brandonroberts Oct 11, 2022
0a046de
chore: fix standalone components and imports
brandonroberts Oct 11, 2022
e018f96
refactor: use prefix for pathMatch if not index route
brandonroberts Oct 11, 2022
1e943ef
chore: fix currency pipe import
brandonroberts Oct 11, 2022
f315e52
refactor: rename Module type to RouteExport
brandonroberts Oct 11, 2022
6eeba97
chore: add unit tests for routes
brandonroberts Oct 11, 2022
9114786
chore: rename internal function
brandonroberts Oct 11, 2022
6bb9ca3
chore: added more tests
brandonroberts Oct 13, 2022
00550aa
refactor: update regex for .ts file matching
brandonroberts Oct 13, 2022
f18696c
chore: update regex
brandonroberts Oct 13, 2022
b532019
chore: reuse regex for matching
brandonroberts Oct 13, 2022
3c938ff
fix: fix regex
brandonroberts Oct 13, 2022
b496388
chore: remove console.log
brandonroberts Oct 14, 2022
df17233
refactor: rename injectRoute to injectActivatedRoute
brandonroberts Oct 14, 2022
7612613
chore: update example app to use inject function
brandonroberts Oct 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"analog-app-e2e-cypress": "apps/analog-app-e2e-cypress",
"analog-app-e2e-playwright": "apps/analog-app-e2e-playwright",
"astro-angular": "packages/astro-angular",
"astro-app": "apps/astro-app",
"astro-app-e2e-playwright": "apps/astro-app-e2e-playwright",
"create-analog": "packages/create-analog",
"docs-app": "apps/docs-app",
"vite-plugin-angular": "packages/vite-plugin-angular",
"astro-app": "apps/astro-app",
"astro-app-e2e-playwright": "apps/astro-app-e2e-playwright"
"router": "packages/router",
"vite-plugin-angular": "packages/vite-plugin-angular"
}
}
4 changes: 0 additions & 4 deletions apps/analog-app/src/app/app.component.css

This file was deleted.

6 changes: 0 additions & 6 deletions apps/analog-app/src/app/app.component.html

This file was deleted.

31 changes: 18 additions & 13 deletions apps/analog-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Component } from '@angular/core';
import { RouterModule } from '@angular/router';

import { TopBarComponent } from './top-bar/top-bar.component';

@Component({
selector: 'analogjs-root',
standalone: true,
imports: [TopBarComponent, RouterModule],
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent { }
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';

import { TopBarComponent } from './top-bar/top-bar.component';

@Component({
selector: 'analogjs-root',
standalone: true,
imports: [TopBarComponent, RouterOutlet],
template: `
<app-top-bar></app-top-bar>

<div class="container">
<router-outlet></router-outlet>
</div>
`,
})
export class AppComponent {}
2 changes: 0 additions & 2 deletions apps/analog-app/src/app/cart/cart.component.css

This file was deleted.

32 changes: 0 additions & 32 deletions apps/analog-app/src/app/cart/cart.component.html

This file was deleted.

34 changes: 0 additions & 34 deletions apps/analog-app/src/app/cart/cart.component.ts

This file was deleted.

This file was deleted.

This file was deleted.

35 changes: 18 additions & 17 deletions apps/analog-app/src/app/product-alerts/product-alerts.component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { CommonModule } from '@angular/common';
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Product } from '../products';

@Component({
selector: 'app-product-alerts',
standalone: true,
imports: [CommonModule],
templateUrl: './product-alerts.component.html',
styleUrls: ['./product-alerts.component.css']
})
export class ProductAlertsComponent {
@Input() product: Product | undefined;
@Output() notify = new EventEmitter();
}


import { NgIf } from '@angular/common';
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Product } from '../products';

@Component({
selector: 'app-product-alerts',
standalone: true,
imports: [NgIf],
template: `
<p *ngIf="product && product.price > 700">
<button type="button" (click)="notify.emit()">Notify Me</button>
</p>
`,
})
export class ProductAlertsComponent {
@Input() product: Product | undefined;
@Output() notify = new EventEmitter();
}

This file was deleted.

This file was deleted.

This file was deleted.

28 changes: 0 additions & 28 deletions apps/analog-app/src/app/product-list/product-list.component.html

This file was deleted.

This file was deleted.

37 changes: 0 additions & 37 deletions apps/analog-app/src/app/product-list/product-list.component.ts

This file was deleted.

26 changes: 0 additions & 26 deletions apps/analog-app/src/app/routes.ts

This file was deleted.

56 changes: 56 additions & 0 deletions apps/analog-app/src/app/routes/cart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { CurrencyPipe, NgForOf } from '@angular/common';
import { Component, inject } from '@angular/core';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { RouterLinkWithHref } from '@angular/router';

import { CartService } from '../cart.service';

@Component({
selector: 'app-cart',
standalone: true,
imports: [RouterLinkWithHref, NgForOf, CurrencyPipe, ReactiveFormsModule],
template: `
<h3>Cart</h3>

<p>
<a routerLink="/shipping">Shipping Prices</a>
</p>

<div class="cart-item" *ngFor="let item of items">
<span>{{ item.name }} </span>
<span>{{ item.price | currency }}</span>
</div>

<form [formGroup]="checkoutForm" (ngSubmit)="onSubmit()">
<div>
<label for="name"> Name </label>
<input id="name" type="text" formControlName="name" />
</div>

<div>
<label for="address"> Address </label>
<input id="address" type="text" formControlName="address" />
</div>

<button class="button" type="submit">Purchase</button>
</form>
`,
})
export default class CartComponent {
private cartService = inject(CartService);
private formBuilder = inject(FormBuilder);

items = this.cartService.getItems();

checkoutForm = this.formBuilder.group({
name: '',
address: '',
});

onSubmit(): void {
// Process checkout data here
this.items = this.cartService.clearCart();
console.warn('Your order has been submitted', this.checkoutForm.value);
this.checkoutForm.reset();
}
}
Loading