Module: utils
Functions
assertUnreachable
▸ assertUnreachable(variable
, message?
): never
Parameters
Name | Type |
---|---|
variable | never |
message? | string |
Returns
never
Defined in
packages/webapp-libs/webapp-core/src/utils/assertUnreachable.tsx:1
camelCaseKeys
▸ camelCaseKeys(object
): Record
<string
, any
>
Translate all top-level keys of the given object
to camelCase.
Parameters
Name | Type |
---|---|
object | Record <string , any > |
Returns
Record
<string
, any
>
Defined in
packages/webapp-libs/webapp-core/src/utils/object.ts:6
getLocalePath
▸ getLocalePath(p
): string
Parameters
Name | Type |
---|---|
p | string |
Returns
string
Defined in
packages/webapp-libs/webapp-core/src/utils/path.ts:3
nestedPath
▸ nestedPath<T
>(root
, nestedRoutes
): { index
: string
} & T
& { getLocalePath
: (route
: keyof T
) => string
; getRelativeUrl
: (route
: keyof T
) => T
[keyof T
] }
Helper function to define typed nested route config
Type parameters
Name | Type |
---|---|
T | extends object |
Parameters
Name | Type |
---|---|
root | string |
nestedRoutes | T |
Returns
{ index
: string
} & T
& { getLocalePath
: (route
: keyof T
) => string
; getRelativeUrl
: (route
: keyof T
) => T
[keyof T
] }
Example
In route config
import { nestedPath } from '@shipfast/webapp-core/utils';
export const RoutesConfig = {
example: nestedPath('example', {
list: '',
details: ':id',
edit: ':id/edit',
add: 'add',
}),
};
Example
When defining a route component
import { Route } from 'react-router-dom';
<Route path={RoutesConfig.example.edit} element={<CrudDemoItemEdit />} />
Example
When creating a link
import { useGenerateLocalePath } from '@shipfast/webapp-core/hooks';
import { Link } from 'react-router-dom';
const Example = () => {
const generateLocalePath = useGenerateLocalePath();
return (
<Link to={generateLocalePath(RoutesConfig.example.edit, { id: 'item-id' })}>
Press me
</Link>
)
}