schultek / jaspr

Modern web framework for building websites in Dart. Supports SPAs and SSR.
https://jasprpad.schultek.de
MIT License
1k stars 59 forks source link

feat: jaspr_router logging #191

Open dinko7 opened 3 months ago

dinko7 commented 3 months ago

Description

GoRouter has a debugLogDiagnostics property which can be set at the router level to show logs during navigation.

Adding this to jaspr_router would help developers debug issues during routing.

The output would be identical to GoRouter's:

Output on startup:

Router: known full paths for routes:
Router:   => /
Router:   =>   /family/:fid
Router:   =>     /family/:fid/person/:pid
Router: known full paths for route names:
Router:   home => /
Router:   family => /family/:fid
Router:   person => /family/:fid/person/:pid

Output on route change:

Router: location changed to /
Router: getting location for name: "person", params: {fid: f2, pid: p1}
Router: going to /family/f2/person/p1
Router: location changed to /family/f2/person/p1

Output on error:

Router: Exception: no routes for location: /foobarquux

Contribution

I would be open to implement this. Haven't really taken a deeper look at the code, but this is what I have so far:

Add debugLogDiagnostics property to the Router:

Router({
    required this.routes,
    this.errorBuilder,
    this.redirect,
    this.redirectLimit = 5,
    this.debugLogDiagnostics = false,
  }) 

 final bool debugLogDiagnostics;

Output on startup would be added in the following method:

Future<RouteMatchList> _preload(RouteMatchList match) 

Output on route change would be added in the following method:

 Future<void> _update(
    String location, {
    Object? extra,
    bool updateHistory = true,
    bool replace = false,
  })

Correct me if something is wrong.

schultek commented 3 months ago

Sounds good. I think part of that is already in the implementation (see RouteConfiguration.debugKnownRoutes) but its just not used right now.