Rerender on new route or transition

I’m building a banner ad plug-in. I have a section of the DOM that I need to re-render each time the page transitions. I have attempted (unsuccessfully) both a Widget and Ember Component, but neither are updating. I loaded them via a Plugin Outlet. I even tried to simplify the problem and dump the current timestamp of the load to the screen (rather than a banner), but only get a re-render if I refresh the browser.

Can someone please point me in the right direction for a solution? I’ve been through the main Discourse developer tutorials, BTW. Just seems like I’m missing something simple.

In which place you are trying to render? In Discourse most of the header UI sections will not refresh across page transactions unlike you hit browser refresh.

And can you post your code to see how you are doing it.

The plugin outlet right above the topic list.

Maybe you can try the following code (not tested):

// My plugin initializer
export default {

	name: 'myPlugin',

	initialize(container) {

		// Reopen the router to add a didTransition hook
		const router = container.lookup('router:main')
		router.reopen({
			doSomething: function() {
				// Wait for rendering to be over. THIS DOESN'T WORK IN ALL CASES. 
				// In fact, there is no way to be sure rendering is complete, because 
				// a 'complete rendering' is meaningless (think about a looping DOM  
				// animation)
				Ember.run.schedule('afterRender', null, () => {
					// Do your stuff here
					...
				})
			}.on('didTransition')
		})

	}

}

هل يمكن لأي شخص تقديم مزيد من التوجيه بشأن هذا؟

هل يمكنك شرح ما تحاول تحقيقه، من فضلك؟

نحتاج إلى إضافة مكون في منطقة التذييل وتحديث محتواه في كل مرة يتم فيها تحميل الصفحة عند زيارة المستخدم لموضوع. إنه شريط تمرير يحتوي على أهم موضوعات مجتمعنا وهو مرئي فقط لصفحات الموضوعات للمستخدمين المجهولين. لذا، عند زيارة المستخدم لكل موضوع موجود في شريط التمرير، يجب إزالة هذا الشريحة من المكون. إن تثبيته باستخدام منفذ التذييل أدناه لا يعيد عرض المكون.

عندما يتم عرض “التذييل” في Discourse، يرسل التطبيق “حدثًا”

الحدث هو inserted-custom-html:footer

يمكنك استخدام هذا الحدث لتحديث محتوى التذييل الخاص بك على النحو التالي

api.onAppEvent("inserted-custom-html:footer", () => {
  // أضف كود JavaScript الخاص بك هنا
});

هناك بعض التفاصيل الإضافية هنا.

ينبغي أن يعمل هذا بما تحاول تحقيقه. إذا لم يعمل، فأخبرني - وانشر الكود الذي تستخدمه.

إعجابَين (2)

أود وضع محتوى ديناميكي في أعلى الصفحة الرئيسية (فقط).

ما هي أفضل الممارسات حاليًا لإعادة عرضه مع كل انتقال للصفحة الرئيسية؟

سأكون ممتنًا لأي رابط لمكون إضافي موجود يستخدم هذا..