Initializing interactive elements on the web page

The initializePage function will get called only once when the web page is first loaded. Its role is to initialize the functionality that enables user interactivity with the client-side web application. This would be the respective initialize function for a given web page, which would be responsible for initializing event handlers and reusable components (cogs).

Inside the initializePage function, we will extract the routeName from the PathName property of the window's location object; the route name for the http://localhost:8080/about URL will be "about":

l := strings.Split(env.Window.Location().Pathname, "/")
routeName := l[1]

if routeName == "" {
routeName = "index"
}

If no routeName is available, we will assign the value of "index", the route name for the home page, to routeName.

We will declare a switch block on routeName, and here's the corresponding case statement that handles the scenario where routeName is equal to "about":

case "about":
handlers.InitializeAboutPage(env)

The designated initialize function for the About page, is the InitializeAboutPage function, which is defined in the handlers package. This function is responsible for enabling user interactivity on the About page.

Now that we've set up the template set on the client-side, and registered the /about route, let's go ahead and take a look at the client-side About page handler function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.29.71