我嘗試使用route_hierarchical/client.dart
中的路由器來偵聽onpopstate事件並在我的index.html中啓用/禁用<div>
。 (在stagehand.pub dart插件中的示例) 如果這是通過index.html中的正常<a href="/relativePath">
完成的,它可以工作。 但如果我嘗試通過button.onClick.listen()
處理程序中,我打電話更改路徑:window.location.assign()不被路由器在飛鏢中捕獲
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>
...
看起來像一個bug,請在http://dartbug.com報告)。您可以嘗試'window.location.href = xxx'(另請參閱http://stackoverflow.com/questions/13109233) – 2015-04-01 14:07:14
感謝您的回覆,我之前看到過這篇文章,但不幸的是,href setter也無法正常工作: - ( – raptaML 2015-04-01 14:31:14