forked from analogjs/analog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(router): add support for visualizing routes for debugging (analo…
- Loading branch information
1 parent
2b18dc2
commit e204a71
Showing
11 changed files
with
261 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Component } from '@angular/core'; | ||
import { RouterOutlet } from '@angular/router'; | ||
|
||
@Component({ | ||
imports: [RouterOutlet], | ||
template: ` <router-outlet /> `, | ||
}) | ||
export default class AuthLayoutPageComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
template: ` <h2>SignUp</h2> `, | ||
}) | ||
export default class SignupPageComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
import { injectDebugRoutes, DebugRoute } from './routes'; | ||
|
||
type CollectedRoute = { | ||
path: string; | ||
filename: string; | ||
file: string; | ||
isLayout: boolean; | ||
}; | ||
|
||
@Component({ | ||
selector: 'analogjs-debug-routes-page', | ||
standalone: true, | ||
template: ` | ||
<h2>Routes</h2> | ||
<div class="table-container"> | ||
<div class="table-header"> | ||
<div class="header-cell">Route Path</div> | ||
<div class="header-cell">File</div> | ||
<div class="header-cell">Type</div> | ||
</div> | ||
<div class="table-body"> | ||
@for(collectedRoute of collectedRoutes; track collectedRoute.filename) { | ||
<div class="table-row"> | ||
<div class="table-cell">{{ collectedRoute.path }}</div> | ||
<div class="table-cell" [title]="collectedRoute.filename"> | ||
{{ collectedRoute.file }} | ||
</div> | ||
<div class="table-cell"> | ||
{{ collectedRoute.isLayout ? 'Layout' : 'Page' }} | ||
</div> | ||
</div> | ||
} | ||
</div> | ||
</div> | ||
`, | ||
styles: ` | ||
:host { | ||
width: 100%; | ||
} | ||
.table-container { | ||
width: 100%; | ||
max-width: 900px; | ||
margin: 0 auto; | ||
background: white; | ||
border-radius: 8px; | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); | ||
overflow: hidden; | ||
} | ||
.table-header { | ||
display: grid; | ||
grid-template-columns: repeat(3, 1fr); | ||
background: gray; | ||
border-bottom: 2px solid #e5e7eb; | ||
} | ||
.header-cell { | ||
padding: 16px 24px; | ||
font-weight: 600; | ||
text-transform: uppercase; | ||
font-size: 14px; | ||
letter-spacing: 0.05em; | ||
color: white; | ||
} | ||
.table-body { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
.table-row { | ||
display: grid; | ||
grid-template-columns: repeat(3, 1fr); | ||
border-bottom: 1px solid #e5e7eb; | ||
transition: background-color 0.2s ease; | ||
} | ||
.table-row:last-child { | ||
border-bottom: none; | ||
} | ||
.table-row:hover { | ||
background-color: #f9fafb; | ||
} | ||
.table-cell { | ||
padding: 16px 24px; | ||
font-size: 16px; | ||
color: #4b5563; | ||
} | ||
@media (max-width: 640px) { | ||
.table-container { | ||
border-radius: 0; | ||
margin: 0; | ||
} | ||
.header-cell, | ||
.table-cell { | ||
padding: 12px 16px; | ||
} | ||
} | ||
`, | ||
}) | ||
export default class DebugRoutesComponent { | ||
collectedRoutes: CollectedRoute[] = []; | ||
debugRoutes = injectDebugRoutes(); | ||
|
||
ngOnInit() { | ||
this.traverseRoutes(this.debugRoutes); | ||
} | ||
|
||
traverseRoutes(routes: DebugRoute[], parent?: string) { | ||
routes.forEach((route) => { | ||
this.collectedRoutes.push({ | ||
path: route.isLayout | ||
? `${parent ? `/${parent}` : ''}${route.path ? `/${route.path}` : ''}` | ||
: `${parent ? `/${parent}` : ''}${ | ||
route.path ? `/${route.path}` : '/' | ||
}`, | ||
filename: route.filename, | ||
file: route.filename?.replace(/(^.*)pages\//, '') || '', | ||
isLayout: route.isLayout, | ||
}); | ||
|
||
if (route.children) { | ||
this.traverseRoutes(route.children, route.path || ''); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ROUTES } from '@angular/router'; | ||
|
||
/** | ||
* Provides routes that provide additional | ||
* pages for displaying and debugging | ||
* routes. | ||
*/ | ||
export function withDebugRoutes() { | ||
const routes = [ | ||
{ | ||
path: '__analog/routes', | ||
loadComponent: () => import('./debug.page'), | ||
}, | ||
]; | ||
|
||
return { | ||
ɵkind: 101 as number, | ||
ɵproviders: [{ provide: ROUTES, useValue: routes, multi: true }], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { inject, InjectionToken } from '@angular/core'; | ||
import { Route } from '@angular/router'; | ||
|
||
import { | ||
ANALOG_CONTENT_ROUTE_FILES, | ||
ANALOG_ROUTE_FILES, | ||
createRoutes, | ||
} from '../routes'; | ||
|
||
export const DEBUG_ROUTES = new InjectionToken( | ||
'@analogjs/router debug routes', | ||
{ | ||
providedIn: 'root', | ||
factory() { | ||
const debugRoutes = createRoutes( | ||
{ | ||
...ANALOG_ROUTE_FILES, | ||
...ANALOG_CONTENT_ROUTE_FILES, | ||
}, | ||
true | ||
); | ||
|
||
return debugRoutes as (Route & DebugRoute)[]; | ||
}, | ||
} | ||
); | ||
|
||
export type DebugRoute = { | ||
path: string; | ||
filename: string; | ||
isLayout: boolean; | ||
children?: DebugRoute[]; | ||
}; | ||
|
||
export function injectDebugRoutes() { | ||
return inject(DEBUG_ROUTES); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters