Skip to content

Commit

Permalink
Support Exclusive Routing and autoCache at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
kuu12 committed Aug 27, 2018
1 parent cf50081 commit ad9cd12
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 10 deletions.
8 changes: 7 additions & 1 deletion demo/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ class App extends React.Component {
render() {
return (
<div id="app">
<NavigationBar router={this.props.router} token={this.state.token} />
{
this.props.router.pathname !== '/login' &&
<NavigationBar
router={this.props.router}
token={this.state.token}
/>
}
<Log id="app" data={this.props} />

<Basic path="/basic" title="Basic Route" />
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="/kuu12" />,
<App basename="" />,
root,
);
4 changes: 3 additions & 1 deletion demo/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ const Log = ({ id, data }) => {
return null;
};

export default Log;
export default Log;

window.Log = Log;
10 changes: 9 additions & 1 deletion demo/rollup.demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const config = {
format: 'umd',
file: './dist/demo.bundle.js',
sourcemap: true,
globals: {
react: 'React',
'react-dom': 'ReactDOM',
}
},
plugins: [
resolve({
Expand All @@ -33,7 +37,11 @@ const config = {
uglify({
mangle: { toplevel: true }
})
]
],
watch: {
include: ['../src/**', './**'],
exclude: 'rollup.demo.js',
}
};

export default config;
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "less-router",
"version": "1.7.1",
"version": "1.7.2",
"description": "A very easy React router component but full functionally.",
"main": "src/index.jsx",
"scripts": {
"start": "rollup -c ./demo/rollup.demo.js --environment NODE_ENV:production",
"start": "rollup -c ./demo/rollup.demo.js --watch --environment NODE_ENV:production",
"install": "npm run clean && npm run build",
"clean": "node -e \"require('fs-extra').emptyDirSync('./dist')\"",
"build": "rollup -c --environment NODE_ENV:production && rollup -c --environment NODE_ENV:development",
Expand Down Expand Up @@ -41,6 +41,7 @@
"eslint-plugin-react": "^7.10.0",
"fs-extra": "^7.0.0",
"jest": "^23.4.2",
"livereload": "^0.7.0",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"rollup": "^0.64.1",
Expand Down
1 change: 0 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const Routing = arg => {
return <OneOf>{arg.children}</OneOf>;
}
};

export default Routing;
export {
Routing,
Expand Down
6 changes: 3 additions & 3 deletions src/one-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import matching from './path/match';
const OneOf = ({ children }) => {
let found = false;

return [].concat(children).filter(child => {
return [].concat(children).map(child => {
const { parentPath, path } = child.props;
const { match, cached } = matching(
parentPath, path, proxy.router.pathname,
);
if (found) {
return !match && cached;
return !match && cached ? child : <div />;
} else {
if (match) found = match;
return match || cached;
return match || cached ? child : <div />;
}
});
};
Expand Down

0 comments on commit ad9cd12

Please sign in to comment.