schultek / jaspr

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

fix: Router with redirect in server mode #204

Closed carmas123 closed 2 months ago

carmas123 commented 3 months ago

Description I try to use redirect into Router but when I try to use it I got always an exception.

Steps To Reproduce

Simply add a redirect to a base app created with Jaspr-CLI, like this:

  @override
  Iterable<Component> build(BuildContext context) sync* {
    yield div(classes: 'main', [
      const Header(),
      Router(
        routes: [
          Route(
              path: '/',
              title: 'Home',
              builder: (context, state) => const Home()),
          Route(
              path: '/about',
              title: 'About',
              builder: (context, state) => const About()),
        ],
        redirect: (context, state) => "/",
      ),
    ]);
  }

With this I try to redirect all to home page and I got this when I try to navigate into /about path:

[SERVER] [ERROR] ERROR - 2024-04-06 01:04:59.690111
[SERVER] [ERROR]
[SERVER] [ERROR] GET /about
[SERVER] [ERROR] Error thrown by handler.
[SERVER] [ERROR] UnimplementedError: Routing unavailable on the server
[SERVER] [ERROR] package:jaspr_router/src/platform/platform_server.dart 24:5  HistoryManagerImpl.replace
[SERVER] [ERROR] package:jaspr_router/src/router.dart 102:41                  RouterState.initRoutes.<fn>
schultek commented 3 months ago

Oh I see, that error should only come when trying to do Router.push() from the server, but not for resirects

schultek commented 2 months ago

This is now fixed on main. Will be part of the next release.