React Aria components such as Link, Menu, Tabs, and Table transform elements into clickable links that navigate when clicked. These components utilize the href prop to render as an <a> tag, supporting attributes like target and download.
User interactions with these links vary by component. For instance, one might use arrow keys to navigate tabs or press enter to open a link within a ComboBox. With the href prop, React Aria facilitates seamless navigation for each component.
Typically, links perform the default browser action when clicked. However, many applications employ client-side routers to prevent full page reloads. The RouterProvider configures React Aria components to integrate with your client-side router. Simply set it up at the root, and any React Aria component with an href will automatically utilize your router.
Note that links to external sites will default to the browser's native navigation, and links not targeting "_self", using the download attribute, or modified with keys like Command or Alt, will also follow the browser's native behavior.
The RouterProvider component accepts two properties: navigate and useHref. Assign navigate to a function from your routing framework that handles client-side navigation. useHref is optional and modifies a router-specific href to a standard HTML href, such as by adding a base path. Below are setup examples for various frameworks.
To integrate with Inertia.js, you must first declare it in your .d.ts file, such as in global.d.ts.
Next, execute ziggy:generate to generate the Ziggy routes in your terminal.
Then, proceed to alias 'ziggy-js' in your vite.config.ts file.
Now, create the provider file in resources/js/components/providers.tsx and add the following code:
If you're not sure what is theme-provider, refer to the Theme Provider section. After that, go to your resources/js/app.tsx you can encapsulate <App/> within Providers as follows:
I don't know if you need this or not, but if you care about ssr.tsx, you can add the following code:
The useRouter hook from next/navigation provides a router object for navigation purposes. The RouterProvider should be implemented in a client component at the root of each page or layout that contains React Aria links. Create a new client component in the app folder named provider.tsx for this purpose or combine it with other top-level providers as outlined in the Next.js documentation.
Then, in app/layout.tsx or your main layout file, enclose the children components within the ClientProviders component.
If you are using a different framework or router provider not mentioned above, refer to the React Aria Components Docs for additional information on integrating React Aria components with various routers and frameworks.