Skip to content

Commit 34bef1c

Browse files
author
Trixon
committed
Fixed AppRoute component. Solved issue with passing params to components from React Router. Edited readme.
1 parent 9f185b7 commit 34bef1c

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
![](https://habrastorage.org/webt/uk/yi/uy/ukyiuyzyeahoi3rebyllgcqv8ao.png)
2+
3+
Project template available on [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=NikolayMaev.ReactCoreBoilerplate).
4+
5+
# Changes
6+
Version | Date | Description
7+
---|---|---
8+
1.1 | 2018-10-16 | Fixed `AppRoute` component. Solved issue with passing params to components from React Router.
9+
110
# Description
211
React Core Boilerplate is a starting point for building universal/isomorphic React applications with ASP.NET Core 2.
312
It bases on the TypeScript and other libraries for creating powerfull web applications.
413
All work fine out of the box. Also helpful for newbies.
14+
In project exists fake authorization system, you can change it to Identity or another.
515

616
# Usage
717

Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
import { Route, RouteProps, Redirect } from "react-router";
22
import * as React from "react";
3-
import AccountService from "@Services/AccountService";
43
import Globals from "@Globals";
54

6-
type Props = {layout: React.ComponentClass<any>;} & RouteProps;
5+
export interface IProps extends RouteProps {
6+
layout: React.ComponentClass<any>;
7+
}
78

8-
export default class AppRoute extends React.Component<Props, {}> {
9-
constructor(props: Props) {
10-
super(props);
11-
}
12-
render() {
13-
var isLoginPath = this.props.path === "/#";
14-
if (!Globals.isAuthenticated && !isLoginPath) {
15-
return <Redirect to="/#"/>;
16-
}
17-
if (Globals.isAuthenticated && isLoginPath) {
18-
return <Redirect to="/"/>;
19-
}
20-
var getChildrenFn =
21-
(props) =>
22-
React.createElement(
23-
this.props.component as any,
24-
React.createElement(this.props.component as any, props)
25-
);
9+
export const AppRoute = ({ component: Component, layout: Layout, path: Path, ...rest }: IProps) => {
2610

27-
return <Route render={(props) => React.createElement(this.props.layout, props, getChildrenFn(props))} />;
11+
var isLoginPath = Path === "/#";
12+
if (!Globals.isAuthenticated && !isLoginPath) {
13+
return <Redirect to="/#" />;
14+
}
15+
if (Globals.isAuthenticated && isLoginPath) {
16+
return <Redirect to="/" />;
2817
}
18+
19+
return <Route {...rest} render={props => (
20+
<Layout>
21+
<Component {...props} />
22+
</Layout>
23+
)} />;
2924
}

ReactCoreBoilerplate/ClientApp/routes.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import AuthorizedLayout from '@Layouts/authorizedLayout';
22
import GuestLayout from "@Layouts/guestLayout";
33
import LoginPage from '@Pages/#Page';
4-
import AppRoute from "@Components/shared/AppRoute";
4+
import { AppRoute } from "@Components/shared/AppRoute";
55
import * as React from 'react';
66
import { Switch, Route, BrowserRouter } from 'react-router-dom';
77
import HomePage from '@Pages/HomePage';
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
In project exists fake authorization system, you can change it to Identity or another.
2+
More info: https://github.com/NickMaev/react-core-boilerplate
3+
4+
# Installation
5+
1. At the first run you must close the project if it runs in Visual Studio or another IDE.
6+
Open project's folder in console and run command `npm install`.
7+
2. Type `npm run build:dev` for development, it will compile the main and vendor bundle.
8+
3. Run project.
9+
10+
# Modify WebPack vendor config
11+
If you modify the WebPack vendor config, you must manually recompile the vendor bundle.
12+
Type `npm run build:dev` to do this.

0 commit comments

Comments
 (0)