InferSharedProps and dynamic root view
Changes
InferSharedProps
One thing that was missing was the ability to have shared props automatically typesafe client side. This is now possible thanks to InferSharedProps
. To use it, you'll need to modify your config/inertia.ts
configuration file as follows :
import { defineConfig } from '@adonisjs/inertia';
import type { InferSharedProps } from '@adonisjs/inertia/types';
const inertiaConfig = defineConfig({
sharedData: {
mySharedData: 'foo'
},
});
export default inertiaConfig;
declare module '@adonisjs/inertia/types' {
export interface SharedProps extends InferSharedProps<typeof inertiaConfig> {
// If necessary, you can also manually add certain
// shared props, which would be shared from some middleware for example
manuallyAddedSharedProps: number;
}
}
Also make sure to include this reference directive in your inertia/app/app.tsx
/// <reference path="../../config/inertia.ts" />
Then, if you are already using InferPageProps
the SharedProps will be automatically added to it.
Documentation : https://docs.adonisjs.com/guides/inertia#shared-props
Dynamic root view
Sometimes you may need to define a different root view for another part of your application. Now you can, you can pass a function into the config:
import { defineConfig } from ‘@adonisjs/inertia’
export default defineConfig({
rootView: ({ request }: HttpContext) => {
if (request.url().startsWith('/admin')) {
return 'admin_layout';
}
return 'inertia_layout';
},
})
Starter kit example route
The starter-kit example route will now be available on /
, rather than /inertia
as this was a source of confusion for some users.
Commits
- refactor: add starter example route at
/
(71b8e5e) - feat: add InferSharedProps type (388553e)
- feat: dynamic root view (318d608)
- chore: update dependencies (dd6e121)
- test: fix failing test (1192c9a)
- chore: remove unused import (e4ce29d)
Full Changelog: v1.0.0-28...v1.0.0-29