In This Article
usePageLocation
A React hook that provides access to the currently rendered dashboard page's location data. A component using this hook re-renders whenever the current page's URL changes.
Signature
Copy
1() => PageLocation
Returns
A PageLocation
object:
Copy
1{2 pageId: string;3 pathname: string;4 search?: string;5 hash?: string;6}
Name | Type | Description |
---|---|---|
pageId | string | ID of the current page. |
pathname | string | Any parts of the current URL path appended to the page's full URL path. Learn more. |
search | string | Optional. The current URL's query string. |
hash | string | Optional. The current URL's fragment identifier. |
About pathname
The value of pathname
is any part of the URL path that comes after the route to the current dashboard page.
For third-party app dashboard pages, this is anything appended to the URL after the Relative route value that you set when creating the dashboard page extension in the Wix Developers Center.
Examples
In order to set up a dashboard client for React, please refer to the setup guide.
Client side routing
In this example, we use the pathname
returned by usePageLocation()
to define which view the component rendered.
Copy
1import { withDashboard, usePageLocation } from '@wix/dashboard-react';2
3export default withDashboard(() => {4 const { pathname } = usePageLocation();5 6 if (pathname.startsWith("/view-1")) {7 return <div>View #1</div>8 })9 if (pathname.startsWith("/view-2")) {10 return <div>View #2</div>11 }12 return <div>Unknown route</div>13});
Was this helpful?
Yes
No