# Halaman View

Update file src/helper/path.js

```javascript
export const PATH_URL = {
  BASE: "/",
  ABOUT: "/tentang-kami",
  USER_LIST: "/admin/users",
  USER_CREATE: "/admin/users/add",
  USER_VIEW: "/admin/users/:id"
}
```

Buat file src/routes/UserView\.svelte

```javascript
<script>
  import { onMount } from "svelte"
  import Navigation from "../components/Navigation.svelte"
  import { HOST_URL } from "../env"
  import { notifications } from "../helper/toast"
  import Input from "../components/Input.svelte"
  
  export let id

  let isLoading = false
  let user = {}
 
  function reqListener () {
    user = JSON.parse(this.responseText)
  }

  const fetchData = async() => {
    var oReq = new XMLHttpRequest()
    oReq.addEventListener("load", reqListener)
    oReq.open("GET", HOST_URL+ "/users/"+id)
    oReq.send()
  };

  onMount(async () => {
		try {
			isLoading = true
			await fetchData()
			isLoading = false
    } catch(e) {
			isLoading = false;
      notifications.danger(e.message)
    }
	})
  
</script>

<Navigation />
<main>
  <h1>View User</h1>
  <Input label="Email" name="email" value={user.email} disabled />
  <Input label="Name" name="name" value={user.name} disabled />
  <Input label="Age" name="age" value={user.age} disabled />
</main>
```

Update file src/App.svelte

```javascript
<script>
	import { Router, Route } from "svelte-routing"
	import About from "./routes/About.svelte"
	import Home from "./routes/Home.svelte"
	import { PATH_URL } from "./helper/path"
	import UserList from "./routes/UserList.svelte"
	import ProtectedRoute from "./ProtectedRoute.svelte"
	import Toast from "./components/Toast.svelte"
	import UserAdd from "./routes/UserAdd.svelte"
	import UserView from "./routes/UserView.svelte"
</script>

<Router>
	<Route path={PATH_URL.BASE} component={Home}/>
	<Route path={PATH_URL.ABOUT} component={About}/>
	<ProtectedRoute path={PATH_URL.USER_LIST} component={UserList} />
	<ProtectedRoute path={PATH_URL.USER_CREATE} component={UserAdd} />
	<ProtectedRoute path={PATH_URL.USER_VIEW} component={UserView} let:params>
		<UserView id="{params.id}"/>
	</ProtectedRoute>
</Router>
<Toast/>
```

Pada file src/routes/UserList.svelte ubah fungsi onView

```javascript
  const onView = (event) => {
    let id = event.target.dataset.id
    navigate("/admin/users/"+id, { replace: true })
  }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seri-belajar-pemrograman.rijalasepnugroho.com/svelte/halaman-view.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
