Skip to content

Commit

Permalink
Adding views and routes
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-commit committed Oct 16, 2019
1 parent 7b44277 commit be1209d
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 12 deletions.
7 changes: 7 additions & 0 deletions config/react.go
Expand Up @@ -16,9 +16,16 @@ type reactAccount struct {
Enabled bool
Required bool
}

type reactView struct {
Path string
Component string
}

type React struct {
App reactApp
Account reactAccount
Header reactHeader
Sidenav reactSidenav
Views []reactView
}
6 changes: 5 additions & 1 deletion templates/commit0/commit0.tmpl
Expand Up @@ -28,5 +28,9 @@ react:
required: false
sidenav:
enabled: true

views:
- path: /account
component: account
- path: /
component: home
services:
43 changes: 43 additions & 0 deletions templates/react/public/index.html.tmpl
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>{{ .React.App.Name }}</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
21 changes: 12 additions & 9 deletions templates/react/src/App.js
@@ -1,21 +1,24 @@
import React from 'react';
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import Layout from 'components/layout';
import config from 'config';

const renderView = (view) => {
return (
<Route path={`${view.path}`} component={require(`views/${view.component}`).default} />
)
}

export default function App() {


return (
<Layout>
<Router>
<Switch>
<Route path="/a">
<span>a</span>
</Route>
<Route path="/b">
<span>b</span>
</Route>
<Route path="/">
<span>c</span>
</Route>
{
config.views && config.views.map(renderView)
}
</Switch>
</Router>
</Layout>
Expand Down
12 changes: 11 additions & 1 deletion templates/react/src/config/index.js
Expand Up @@ -11,5 +11,15 @@ export default {
},
sidenav: {
enabled: true,
}
},
views: [
{
path: '/account',
component: 'account',
},
{
path: '/',
component: 'home',
},
],
}
10 changes: 9 additions & 1 deletion templates/react/src/config/index.js.tmpl
Expand Up @@ -11,5 +11,13 @@ export default {
},
sidenav: {
enabled: {{ .React.Sidenav.Enabled }},
}
},
views: [
{{ range .React.Views }}
{
path: '{{ .Path }}',
component: '{{ .Component }}',
},
{{ end }}
],
}
9 changes: 9 additions & 0 deletions templates/react/src/views/account.js
@@ -0,0 +1,9 @@
import React from 'react';

export default function Account() {
return (
<div>
Account
</div>
);
}
9 changes: 9 additions & 0 deletions templates/react/src/views/home.js
@@ -0,0 +1,9 @@
import React from 'react';

export default function Home() {
return (
<div>
Home
</div>
);
}

0 comments on commit be1209d

Please sign in to comment.