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: jasper router base ref problems #200

Closed walsha2 closed 3 months ago

walsha2 commented 3 months ago

Description

A few issues, but they all seem to be related to base definition.

A) Defining base causes error

Placing any value of base in main.html will produce the following error:

<base href="/">
errors.dart:297 Uncaught Error: RangeError (startIndex): Invalid value: Only valid value is 0: 1
    at Object.throw_ [as throw] (errors.dart:297:3)
    at RangeError.checkValueInInterval (errors.dart:312:7)
    at [dartx.replaceFirst] (js_string.dart:86:16)
    at Object.canonicalUri (path_utils.dart:123:16)
    at matching.RouteMatcher.new.findMatch (matching.dart:22:31)
    at parser.RouteInformationParser.new.parseRouteInformation (parser.dart:42:32)
    at [_matchRoute] (router.dart:194:30)
    at router$.RouterState.new.initRoutes (router.dart:99:49)
    at router$.RouterState.new.initState (router.dart:84:7)

The only way to resolve this is to comment out <base href="/"> from main.html. Although, this works, I suspect it causes other downstream issues - see below.

B) Refresh on nested routes

Now without any base defined (due to issue above), when I try to refresh on a nested route, for example:

http://localhost:4322/group/htIWKNGNpNgrDJ6aXBMP

I will get the following error:

router

It looks like the lack of a base definition is now improperly resolving the root path. In this case, it is looking for components/app.client.dart.js in the wrong location.

Steps To Reproduce

Need to put something together.

Doctor Output

  • Dependencies on core packages:
    • jaspr: ^0.11.0
    • jaspr_builder: ^0.11.0 (dev)
    • jaspr_web_compilers: ^4.0.9 (dev)
    • jaspr_riverpod: ^0.3.9
    • jaspr_router: ^0.4.0
  • Rendering mode: server
  • Uses jaspr compilers: true
  • Uses flutter embedding: false