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

Simple jaspr router does not work on client only app #180

Closed walsha2 closed 3 months ago

walsha2 commented 4 months ago

Description

A very simple routing example, mostly taken from the docs, does not seem to work at all. I find this odd... I am either doing something wrong (e.g. docs are out of date) or this is a very fundamental bug that has yet to be reported for jaspr_router?

Hopefully that can be resolved soon so that we can continue to look into jaspr for a real production use case.

Steps To Reproduce

See the repo below, on the routing branch for a complete working example and a README with other context:

https://github.com/walsha2/jaspr-issues/tree/routing

walsha2 commented 4 months ago

@schultek per the README in that example repo, the project was created using the "Client Template". I think that helps narrow down the issue.

If I created and ran the same project using the basic template it seems to work, but now the server is introduced. So, the routing issue has to do with client side only app templates.

Out of curiosity, why is the client only template not the default (in turn matching Flutter web)? This is the simplest possible web app to build and certainly the simplest to deploy. Rationale as to why SSR is the default? The docs state the note below, but Im sure there are nuances here. I found all of the SSR stuff to be a lot more complicated to configure and get going than just a client side app. Im not sure about the "easily adapt" comment.

Templates give you a minimal project to get started. Later on you can easily adapt your project for every architecture and rendering mode

walsha2 commented 4 months ago

One minor note of clarification, in the example repo linked above, this works:

Router.of(context).push('/about');

However, navigating directly to the page does not work and results in a 404 - again, see example repo.

http://localhost:8080/about

It looks like it is completely bypassing the App router?

class App extends StatelessComponent {
  @override
  Iterable<Component> build(BuildContext context) sync* {
    yield Router(routes: [
      Route(path: '/', builder: (context, state) => Home()),
      Route(path: '/about', builder: (context, state) => About()),
    ]);
  }
}
neoacevedo commented 2 months ago

Building as a 'template' view for Laravel, if I include the /about in the web.php route file it works but as a static website (client only) it will launch a 404.

UPDATE: I had to create the directory about, copy the index.html inside it and modify the css and js path to make it work. It is jut like to use the app as SSG not as CSG.