react-router#RouteProps TypeScript Examples

The following examples show how to use react-router#RouteProps. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EpiSpaRouter.tsx    From foundation-lib-spa-core with Apache License 2.0 6 votes vote down vote up
function createRouteNode(route: IRouteConfigItem, basePath = "", key ?: string, ctx ?: IEpiserverContext) : React.ReactElement<RouteProps> {
    
    let createdRoute : string = basePath ? (basePath.substr(-1) === "/" ? basePath.substr(0, -1) : basePath) : "";
    createdRoute = createdRoute + "/" + (route.path ? (route.path.substr(0,1) === "/" ? route.path.substr(1) : route.path) : "")

    if (ctx?.isDebugActive()) console.log('Generating Route Virtual DOM Node', createdRoute, route, key);

    const newRouteProps : RouteProps = {
        children: route.children,
        exact: route.exact,
        location: route.location,
        path: createdRoute,
        sensitive: route.sensitive,
        strict: route.strict,
        render: route.render ? (props: RouteComponentProps) => { return route.render ? route.render({ ...props, routes: route.routes, path: route.path }) : <div/> } : undefined,
        component: route.component ? (props: RouteComponentProps) => { const RouteComponent = route.component || 'div'; return <RouteComponent { ...props } routes={ route.routes } path={ route.path } />} : undefined
    }
    return <Route { ...newRouteProps } key={ key } />
}
Example #2
Source File: NewPostScreen.tsx    From jobsgowhere with MIT License 6 votes vote down vote up
PostScreen: React.FC<RouteProps> = function () {
  const postContext = usePost();
  const location = useLocation();

  const EDIT_POST_PATHNAME = "/posts/edit";

  return (
    <MainSingle>
      <Helmet>
        <title>New Post</title>
      </Helmet>
      <h1>
        {postContext.post?.id && location.pathname === EDIT_POST_PATHNAME
          ? "Edit Post"
          : "New Post"}
      </h1>
      <NewPostForm />
    </MainSingle>
  );
}
Example #3
Source File: ProtectedRoute.tsx    From flame with MIT License 6 votes vote down vote up
ProtectedRoute = ({ ...rest }: RouteProps) => {
  const { isAuthenticated } = useSelector((state: State) => state.auth);

  if (isAuthenticated) {
    return <Route {...rest} />;
  } else {
    return <Redirect to="/settings/app" />;
  }
}