【发布时间】:2015-06-06 04:42:55
【问题描述】:
我尝试使用来自route_hierarchical/client.dart 的路由器来监听 onpopstate 事件并在我的 index.html 中启用/禁用<div>。 (stagehand.pub dart 插件中的示例)
如果这是通过 index.html 中的普通<a href="/relativePath"> 完成的,它可以工作。
但是,如果我尝试通过我调用的button.onClick.listen() 处理程序更改路径:
window.location.assign('/relativePath');
我得到 404 并且路由器没有正确处理我的事件。 该操作是否应该不调用像here 描述的那样被路由器捕获的popstate event?
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>
...
【问题讨论】:
-
看起来像一个错误,请在dartbug.com 报告)。你可以试试
window.location.href = xxx(另见stackoverflow.com/questions/13109233) -
感谢您的回复,我之前看过该帖子,但不幸的是 href setter 也不起作用:-(