Skip to content

Commit

Permalink
Update Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kuu12 committed Aug 28, 2018
1 parent ad9cd12 commit ee4c372
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 39 deletions.
33 changes: 18 additions & 15 deletions demo/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,32 @@ class App extends React.Component {

render() {
return (
<div id="app">
<React.Fragment>
<h4>Demo of <a href="https://github.com/kuu12/less-router">Less-Router</a></h4>
{
this.props.router.pathname !== '/login' &&
<NavigationBar
router={this.props.router}
token={this.state.token}
setToken={this.setToken}
/>
}
<p>
<Basic path="/basic" title="Basic Route" />
<Parameter path="/parameter/:name/:id" title="URL Parameters" />
<Cache path="/cache" title="Cache" autoCache />
<Dynamic path="/dynamic/" title="Dynamic Routing" />
<Login path="/login" title="Login" setToken={this.setToken} />
<Profile path="/profile" title="profile" token={this.state.token} />
<Routing>
<One path="/exclusive/one" title="Exclusive Route 1" />
<Two path="/exclusive/two" title="Exclusive Route 2" autoCache />
<Three path="/exclusive/:any" title="Exclusive Route 3" />
</Routing>
<NotFound notFound title="404 Not Found" />
</p>
<Log id="app" data={this.props} />

<Basic path="/basic" title="Basic Route" />
<Parameter path="/parameter/:name/:id" title="URL Parameters" />
<Cache path="/cache" title="Cache" autoCache />
<Dynamic path="/dynamic/" title="Dynamic Routing" />
<Login path="/login" title="Login" setToken={this.setToken} />
<Profile path="/profile" title="profile" />
<Routing>
<One path="/exclusive/one" title="Exclusive Route 1" />
<Two path="/exclusive/two" title="Exclusive Route 2" autoCache />
<Three path="/exclusive/:any" title="Exclusive Route 3" />
</Routing>
<NotFound notFound title="404 Not Found" />
</div>
</React.Fragment>
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions demo/cache.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ class Cache extends React.Component {
clearInterval(this.timer);
}
render() {
const { router } = this.props;
return (
<div id="cache">
Start Time: {this.state.start}
<br />
Counting: {this.state.count}
<br />
<button name="clear-cache" onClick={async () => {
await router.replace('/');
await router.clearCache('/cache');
console.log('clear');
}}>Back to Home Page and Clear Cache</button>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion demo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ root.id = 'root';
document.body.appendChild(root);

ReactDOM.render(
<App basename="" />,
<App basename="/router-demo" />,
root,
);
7 changes: 6 additions & 1 deletion demo/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ const Login = ({ router, setToken }) => (
<label>
Username: <input defaultValue="kuu12" />
</label>
<br />
<label>
Password: <input type="password" defaultValue="foobar" />
</label>
<br />
<button onClick={() => {
setToken(true);
router.back();
router.replace(
sessionStorage.getItem('loginRedirect') ||
'/'
);
}}>
Submit
</button>
Expand Down
35 changes: 21 additions & 14 deletions demo/navigation-bar.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import React from 'react'
import React from 'react';

const NavigationBar = ({ router, token }) => (
<div id="navigation-bar">
const NavigationBar = ({ router, token, setToken }) => (
<nav id="navigation-bar">
<button name="basic" onClick={() => router.push('/basic')}>Try Basic Use</button>
<button name="parameter" onClick={() => router.push('/parameter/kuu/12')}>Try URL Parameters </button>
<button name="cache" onClick={() => router.push('/cache')}>Try Cache</button>
<button name="dynamic" onClick={() => router.push('/dynamic/')}>Try Dynamic Routing</button>
<button name="one" onClick={() => router.push('/exclusive/one')}>Render First Route</button>
<button name="two" onClick={() => router.push('/exclusive/two')}>Render Second Route</button>
<button name="three" onClick={() => router.push('/exclusive/foobar')}>Render Third Route</button>
<button name="profile" onClick={() => {
if (token) {
router.push('/profile');
} else {
router.push('/login');
}
}}>Check Out My Profile</button>
</div>
<button name="profile" onClick={() => router.push('/profile')}>My Profile (Try Login)</button>
{
token &&
<button name="logout" onClick={() => {
if (window.confirm('Logout?')) {
setToken(null);
router.push('/');
}
}}>Logout</button>
}
<br />
<div>
<span style={{ fontSize: 14 }}>Try Exclusive Routing : </span>
<button name="one" onClick={() => router.push('/exclusive/one')}>Render First Route</button>
<button name="two" onClick={() => router.push('/exclusive/two')}>Render Second Route</button>
<button name="three" onClick={() => router.push('/exclusive/foobar')}>Render Third Route</button>
</div>
</nav>
);

export default NavigationBar;
25 changes: 18 additions & 7 deletions demo/profile.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import React from 'react';
import Routing from '../src';

const Profile = ({ router }) => (
<div id="profile">
My Profile
<br />
balance: $ 100.00
</div>
);
class Profile extends React.Component {
componentDidMount() {
if (!this.props.token) {
sessionStorage.setItem('loginRedirect', '/profile');
this.props.router.push('/login');
alert('Need Login');
}
}
render() {
return (
<div id="profile">
My Profile
<br />
balance: $ 100.00
</div>
);
}
}

export default Routing(Profile);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
"jest": {
"testURL": "http://localhost"
}
}
}

0 comments on commit ee4c372

Please sign in to comment.