Bug fix to pass event object into the onLinkClick function when used in the index.html page

This commit is contained in:
Lukong Isaac
2021-09-14 13:28:46 +01:00
committed by Yohan Lasorsa
parent d24b2c0be3
commit 5b97637d3c

View File

@@ -247,11 +247,13 @@ function onLinkClick(event) {
Let's complete the navigation system by adding bindings to our *Login* and *Logout* links in the HTML. Let's complete the navigation system by adding bindings to our *Login* and *Logout* links in the HTML.
```html ```html
<a href="/dashboard" onclick="onLinkClick()">Login</a> <a href="/dashboard" onclick="onLinkClick(event)">Login</a>
... ...
<a href="/login" onclick="onLinkClick()">Logout</a> <a href="/login" onclick="onLinkClick(event)">Logout</a>
``` ```
The `event` object above, captures the `click` event and passes it to our `onLinkClick` function.
Using the [`onclick`](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick) attribute bind the `click` event to JavaScript code, here the call to the `navigate()` function. Using the [`onclick`](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick) attribute bind the `click` event to JavaScript code, here the call to the `navigate()` function.
Try clicking on these links, you should be now able to navigate between the different screens of your app. Try clicking on these links, you should be now able to navigate between the different screens of your app.