Skip to content

Commit 973e214

Browse files
fussel178Ludwig Richter
authored and
Ludwig Richter
committed
refactor(core): Make the routing argument more general
1 parent 05875a2 commit 973e214

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/telestion-client-core/src/components/pages/lib/build-route.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,27 @@ import { logger } from './logger';
2323
* ```
2424
*/
2525
export function buildRoute(
26-
routing: Routing & { redirectPath: string },
26+
routing: Routing,
2727
page: ReactNode,
2828
isAuthenticated: boolean
2929
): ReactNode {
30-
const key = `comp:${routing.path}:${routing.redirectPath}`;
30+
const { path, exact, type } = routing;
31+
32+
const redirectPath = 'redirectPath' in routing ? routing.redirectPath : '';
33+
const key = `comp:${path}:${redirectPath}`;
3134
const shouldRender =
32-
(routing.type === 'auth' && isAuthenticated) ||
33-
(routing.type === 'unAuth' && !isAuthenticated);
35+
(type === 'auth' && isAuthenticated) ||
36+
(type === 'unAuth' && !isAuthenticated);
3437

3538
logger.debug(
36-
`Route with${routing.exact ? ' exact' : ''} path "${routing.path}" should ${
37-
shouldRender ? 'render' : `redirect to "${routing.redirectPath}"`
39+
`Route with${exact ? ' exact' : ''} path "${path}" should ${
40+
shouldRender ? 'render' : `redirect to "${redirectPath}"`
3841
}`
3942
);
4043

4144
return (
42-
<Route key={key} path={routing.path} exact={routing.exact}>
43-
{shouldRender ? page : <Redirect to={routing.redirectPath} />}
45+
<Route key={key} path={path} exact={exact}>
46+
{shouldRender ? page : <Redirect to={redirectPath} />}
4447
</Route>
4548
);
4649
}

0 commit comments

Comments
 (0)