Page code not working when direct link to page

I have a page with a repeater fed by a database of events and info that displays/hides when the content is present/not-present. Whenever I go directly to the page that hosts this repeater, the code does not run and everything is displayed. If I navigate to it through the site, the code runs as it is designed to. Why is this?

Post your code

Would a link to the page be more beneficial? Here is a snippet that just repeats for the different bits of data.

import wixData from ‘wix-data’ ;
$w ( “#repeater1” ). onItemReady ( ( $w , itemData , index ) => {

if ( itemData . preregOnly ) {
$w ( ‘#text19’ ). show ();
}
else
$w ( ‘#text19’ ). hide ();

if ( itemData . landingPage ) {
$w ( ‘#button1’ ). show ();
}
else
$w ( ‘#button1’ ). hide ();

(continues for other text boxes)

You should put everything (besides the import line) inside $w.onReady:

import wixData from 'wix-data';
$w.onReady(() => {
//put everything here
})