Aaron Aaron - 1 year ago 142
Dart Question

Angular2 Dart with pub serve localhost refresh page 404

In angular2 dart the hashbang is removed from routing by default which makes for nice urls. However, when I run the app with pub serve, I can't refresh any page other than the root or I get a 404 that says for example "Could not find asset web/dashboard in package angular2_quickstart."

I know there's got to be a simple solution.

Is there a way to force pub serve to capture all routes at the host and always serve index.html like single page apps do? Or what is the developer workflow for developing and serving your application locally?

This question is similar, but I'd prefer not to use the hashbang: Angular2 Routing gives 404 when reloading page

Answer Source

pub serve doesn't support PathLocationStrategy

Either you use some proxy that adds support for PathLocationStrategy or you configure Angular2 to use HashLocationStrategy

bootstrap(AppComponent, const Provider(LocationStrategy, useClass: HashLocationStrategy)]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download