Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/routing/authenticated-route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ interface AuthenticatedRouteProps

// #endregion Interfaces

/**
* Locks a route behind authentication. Can optionally redirect a user to another location if
* attempting to access the route while unauthenticated.
*/
const AuthenticatedRoute: React.FC<AuthenticatedRouteProps> = (
props: AuthenticatedRouteProps
) => {
Expand Down
10 changes: 9 additions & 1 deletion src/components/routing/nested-route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface NestedRouteProps extends AuthenticatedRoute {
* Dynamically renders a route and its subroutes, accounting
* for additional custom properties on RouteDefinition
*/
export const NestedRoute = (props: NestedRouteProps) => {
const NestedRoute: React.FC<NestedRouteProps> = (props: NestedRouteProps) => {
const { isAuthenticated, redirectToIfUnauthenticated, route } = props;
const RouteComponent: any = route.authRequired
? AuthenticatedRouteComponent
Expand All @@ -46,3 +46,11 @@ export const NestedRoute = (props: NestedRouteProps) => {
};

// #endregion Component

// -----------------------------------------------------------------------------------------
// #region Exports
// -----------------------------------------------------------------------------------------

export { NestedRoute, NestedRouteProps };

// #endregion Exports
4 changes: 3 additions & 1 deletion src/components/routing/nested-routes-by-property.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ interface NestedRoutesByPropertyProps {
/**
* Renders Route components mapped to a custom property
*/
const NestedRoutesByProperty = (props: NestedRoutesByPropertyProps) => {
const NestedRoutesByProperty: React.FC<NestedRoutesByPropertyProps> = (
props: NestedRoutesByPropertyProps
) => {
if (CollectionUtils.isEmpty(props.routes)) {
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/routing/nested-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ interface NestedRoutesProps extends UnmatchedRoute, AuthenticatedRoute {
* Component to easily render nested sub-route components from a list of routes.
* Commonly used when setting up a layout
*/
const NestedRoutes = (props: NestedRoutesProps) => {
const NestedRoutes: React.FC<NestedRoutesProps> = (
props: NestedRoutesProps
) => {
const {
isAuthenticated,
redirectToIfNotFound,
Expand Down
2 changes: 1 addition & 1 deletion src/components/routing/redirects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface RedirectsProps {
/**
* Simple way to redirect a flat array of RedirectDefinitions
*/
const Redirects = (props: RedirectsProps) => {
const Redirects: React.FC<RedirectsProps> = (props: RedirectsProps) => {
const { redirects } = props;

// TODO: Remove Fragment when issue fixed https://github.com/microsoft/TypeScript/issues/21699
Expand Down
58 changes: 47 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,80 @@
// #region Components
// -----------------------------------------------------------------------------------------

export * from "./components/routing/authenticated-route";
export * from "./components/routing/nested-route";
export * from "./components/routing/nested-routes";
export * from "./components/routing/nested-routes-by-property";
export * from "./components/routing/redirects";
export {
AuthenticatedRoute,
AuthenticatedRouteProps,
} from "./components/routing/authenticated-route";
export {
NestedRoute,
NestedRouteProps,
} from "./components/routing/nested-route";
export {
NestedRoutes,
NestedRoutesProps,
} from "./components/routing/nested-routes";
export {
NestedRoutesByProperty,
NestedRoutesByPropertyProps,
} from "./components/routing/nested-routes-by-property";
export { Redirects, RedirectsProps } from "./components/routing/redirects";

//#endregion Components

// -----------------------------------------------------------------------------------------
// #region Interfaces
// -----------------------------------------------------------------------------------------

export * from "./interfaces/redirect-definition";
export * from "./interfaces/route-definition";
export * from "./interfaces/route-map";
export { RedirectDefinition } from "./interfaces/redirect-definition";
export { RouteDefinition } from "./interfaces/route-definition";
export { RouteMap } from "./interfaces/route-map";

//#endregion Interfaces

// -----------------------------------------------------------------------------------------
// #region Services
// -----------------------------------------------------------------------------------------

export * from "./services/service-factory";
export { ServiceFactory } from "./services/service-factory";

//#endregion Services

// -----------------------------------------------------------------------------------------
// #region Utilities
// -----------------------------------------------------------------------------------------

export * from "./utilities/route-utils";
export { RouteUtils } from "./utilities/route-utils";

//#endregion Utilities

// -----------------------------------------------------------------------------------------
// #region Vendor
// -----------------------------------------------------------------------------------------

export * from "react-router-dom";
// Forwarding everything from react-router-dom as-is, just incase a consumer wants to use some
// specific component or function for their own implemention alongside our library.
export {
generatePath,
Prompt,
MemoryRouter,
RedirectProps,
Redirect,
RouteChildrenProps,
RouteComponentProps,
RouteProps,
Route,
Router,
StaticRouter,
SwitchProps,
Switch,
match,
matchPath,
withRouter,
RouterChildContext,
useHistory,
useLocation,
useParams,
useRouteMatch,
} from "react-router-dom";

//#endregion Vendor
7 changes: 5 additions & 2 deletions src/tests/factories/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from "./route-definition-factory";
export * from "./route-map-factory";
export {
RouteDefinitionFactory,
RouteDefinitionNestedFactory,
} from "./route-definition-factory";
export { RouteMapFactory } from "./route-map-factory";
export { StubResourceRecordFactory } from "andculturecode-javascript-testing";