[英]meteor.js iron-router: prevent static template re-render and glitching?
[英]Using iron-router to go to a certain id section of the page (url#portion) in Meteor.js
我已使用Iron-Router設置了路由,以確保頁面轉到頁面頂部:
Router.route('/services', {
name: 'services',
template: 'services',
onAfterAction: function () {
scrollTop();
}
});
function scrollTop() {
window.scroll(0, 0);
}
但是,如果我在另一條路線上,並且有類似/ services#thisid的鏈接
仍然會將我帶到頁面頂部(而不是帶id = thisid的頁面部分)。
有辦法解決這個問題嗎?
這應該同時解決您的問題和布局覆蓋問題。
Router.configure({
layoutTemplate: 'main',
onAfterAction: function(){
console.log('hash', this.params.hash);
if(!this.params.hash){
scrollTop();
}
}
});
Router.route('/services', {
name: 'services',
template: 'services',
});
Router.route('/inquiry', {
name: 'inquiry',
template: 'inquiry',
layoutTemplate: 'alternate'
});
檢查this.params.hash
可以確保在執行scrollTop之前沒有哈希值。 查詢路由上的layoutTemplate
會覆蓋布局,同時仍要遵守全局onAfterAction。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.