I try to use a Router from route_hierarchical/client.dart
to listen to an onpopstate event and enable/disable a <div>
in my index.html. (Example in stagehand.pub dart plugin)
If this is done via normal <a href="/relativePath">
in index.html, it works.
But if I try to change the path via a button.onClick.listen()
handler in which I call:
window.location.assign('/relativePath');
I get 404 and the router is not handling my event properly. Should that that action not invoke a popstate event which is caught by Router like described here?
handlers.dart
...
button.onClick.listen((_){
window.location.assign('/about');
});
...
router.dart
var router = new Router();
router.root
..addRoute(name: 'about', path: '/about', enter: showAbout)
..addRoute(name: 'login', defaultRoute: true, path: '/', enter: showLogin)
..addRoute(name: 'context', path: '/context', enter: showContext);
router.listen();
}
void showAbout(RouteEvent e) {
// Extremely simple and non-scalable way to show different views.
querySelector('#login').style.display = 'none';
querySelector('#about').style.display = '';
querySelector('#context').style.display = 'none';
} ...
index.html
...
<form>
<button type="button" id="submit" disabled="true" >
Login
</button>
</form>
...