-
-
Notifications
You must be signed in to change notification settings - Fork 287
feat(vite-plugin-angular): add tanstack router style routeGen with JSON-LD #1813
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(vite-plugin-angular): add tanstack router style routeGen with JSON-LD #1813
Conversation
✅ Deploy Preview for analog-ng-app ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-app ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-blog ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@brandonroberts this is an attempt to scratch my own itch. If you like it I hope we could get it in as experimental so it can be iterated. I have an open PR on our internal repo for doing SEO optimization with SSR and I'd love to get something like this in to use. Thx <3 |
Will be restructuring this PR so functionality is isolated to its proper boundary |
I like the idea of type-safe routes. This implementation will make all routes eagerly loaded and needs some more thought around the router with navigation and links. Let's close this PR and open a discussion on the proposal. |
ad7a0b0
to
ca10bc0
Compare
TanStack Router Style Route Tree: Implemented FixesI've addressed concerns about eager loading, plugin integration, and navigation utilities. Below is a detailed summary of the completed changes, with a Before/After Table showing how we resolved each issue. The implementation now aligns with Angular best practices, preserves performance, and enhances developer experience.
Implemented Solutions
Results
Benefits
|
b58a529
to
aa428b5
Compare
MUST CLOSE AFTER: #1839 refactor(platform): migrate to moduleResolution bundler for enhanced performance The only way to get the middleware working with SSR was to consolidate to ESM and remove CommonJS |
aa428b5
to
19e73c9
Compare
19e73c9
to
057a5a1
Compare
c13cb38
to
e432b31
Compare
I've rewritten the Nitro middleware handling system with robustness. Here's what the solution provides: 🎯 Key Improvements1. Comprehensive Error Handling
2. Intelligent Validation
3. Fault-Proof Design
4. Production-Ready Features
🚀 How It Works// 1. Safe module loading with cache invalidation
const module = await viteServer.ssrLoadModule(filePath);
// 2. Multi-level validation
if (!handler || typeof handler !== 'function') {
/* warn & continue */
}
if (!handler.__is_handler__ && handler.length > 1) {
/* warn & continue */
}
// 3. Safe execution wrapper
try {
const result = await handler(createEvent(req, res));
if (!result) next(); // Continue chain
} catch (error) {
console.error(error);
next(); // Never fail the request
} ✅ Benefits
The solution transforms middleware from a potential point of failure into a resilient, self-monitoring system that enhances rather than risks your application's stability! 🛡️ |
I modified the
Key Changes Made
The redirect middleware ( |
43282e2
to
e31caf4
Compare
@brandonroberts I updated the original description of this PR. I left other helpful comments and also I feel I addressed your concern about eagerly loaded routes. I also added comprehensive JSDOC documentation with lessons-learned and pitfalls (discovered over 30 hours doing this), and added a nice debugging feature. I really need this functionality for the https://snyder.tech website 😅😅😅 and, well, this is an Barring any major issues, could we get this into |
I was hoping to get more feedback on this PR before closing but for now, I am going to get it merged into the fork. If there is any refactoring to do, or significant change to functionality, we'll address it in a follow-up. This PR is being closed and accelerated into this fork: ESM Transition Plan for AnalogJS v2.0.0-alpha #1844 | 📢 |
I was hoping to get more feedback on this PR before closing but for now, I am going to get it merged into the fork. If there is any refactoring to do, or significant change to functionality, we'll address it in a follow-up. This PR is being closed and accelerated into this fork: ESM Transition Plan for AnalogJS v2.0.0-alpha #1844 | 📢 |
Summary
This PR introduces an experimental route tree generator for AnalogJS that provides type-safe routing with automatic code generation, inspired by TanStack Router's approach. The feature generates TypeScript interfaces for all routes, enables JSON-LD structured data injection for SEO, and provides comprehensive debugging tools for troubleshooting SSR conflicts.
Motivation & Context
AnalogJS's file-based routing is powerful but lacks compile-time type safety for route parameters and navigation. Developers often face runtime errors due to typos in route paths or missing required parameters. This feature brings the excellent developer experience of TanStack Router's type-safe routing to the Angular ecosystem through AnalogJS.
Additionally, modern web applications require structured data for SEO optimization. This PR also introduces automatic JSON-LD injection during SSR, making it easy to add schema.org structured data to any route.
Changes
Core Features
Route Tree Plugin (
packages/vite-plugin-angular/src/lib/route-tree-plugin.ts
)src/app/pages
directory for.page.ts
filesrouteTree.gen.ts
with type-safe route interfacesrouteMeta
)JSON-LD SSR Plugin (
packages/vite-plugin-angular/src/lib/json-ld-ssr-plugin.ts
)schema-dts
packageAngular Vite Plugin Integration
routeTree
configuration optionConfiguration Options
Generated Type Definitions
The plugin generates comprehensive type definitions including:
AnalogRoutesByPath
- Map routes to component typesAnalogRoutesById
- Access routes by IDRouteParams<T>
- Extract typed parameters for any routeExample Usage
Test Apps Updated
apps/analog-app
: Added example pages with JSON-LD exportsarticle.page.ts
- Article schema exampleproduct.page.ts
- Product schema exampleevent.page.ts
- Event schema exampletest-meta.page.ts
- Route metadata exampleFile Changes Summary
@analogjs/vite-plugin-angular
@analogjs/platform
@analogjs/router
Breaking Changes
None. This is an experimental opt-in feature that requires explicit configuration to enable.
Testing
Documentation
This PR includes comprehensive inline documentation and JSDoc comments. Additional documentation should be added to the AnalogJS docs site covering:
Known Issues & Future Work
SSR Middleware Conflicts: The JSON-LD SSR plugin can conflict with existing middleware during dev server startup. Debug flags are provided to isolate issues.
Future Enhancements:
Checklist
Related Issues
This addresses the need for type-safe routing in AnalogJS applications and brings feature parity with other modern meta-frameworks like TanStack Router and Next.js.
JSON-LD Structured Data
You can export JSON-LD structured data from your page files using
schema-dts
for type-safe SEO optimization: