Skip to content

Commit

Permalink
filter routes
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni committed Apr 24, 2019
1 parent 7c9b3b2 commit 3c2d572
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 2 deletions.
2 changes: 1 addition & 1 deletion initapp/src/menus.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"path":"/"},{"path":"/index/b"}]
[{"path":"/detial/:index?"},{"path":"/home/:index"},{"path":"/"}]
44 changes: 44 additions & 0 deletions initapp/src/models/detial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { query } from '@/services/api';


const DetialModel = {
namespace: 'detial',

state: {
name: ''
},

effects: {
*query({ payload }, { call, put, select }) {
const data = yield call(query, payload);
console.log(data)
yield put({
type: 'save',
payload: { name: data.text },
});

},

},
subscriptions: {
setup({ dispatch, history }) {
return history.listen(({ pathname }) => {
if (pathname === '/detial') {
dispatch({
type: 'query'
})
}
});
}
},
reducers: {
save(state, action) {
return {
...state,
...action.payload,
};
},
},
};

export default DetialModel;
20 changes: 20 additions & 0 deletions initapp/src/pages/detial/$index$.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { connect } from 'dva';
import React, { Component } from 'react';

import styles from './index.less';

@connect(({ detial }) => ({ detial }))
class Page extends Component{
state = {};

render() {
const {
detial: { name },
} = this.props;
console.log(this.props);

return <div className={styles.userCenter}>Hello {name}</div>;
}
}

export default Page;
3 changes: 3 additions & 0 deletions initapp/src/pages/detial/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.userCenter {
font-size: 36px;
}
32 changes: 32 additions & 0 deletions initapp/src/pages/home/$index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { connect } from 'dva';
import React, { Component } from 'react';

import { IndexModelState, ConnectProps } from '@/models/connect';
import { Button } from 'antd';
import styles from './index.less';
const a = '';
interface PageProps extends ConnectProps {
index: IndexModelState;
}

interface PageState {}

@connect(({ index }) => ({ index }))
class Page extends Component<PageProps, PageState> {
state: PageState = {};

componentDidMount() {
const { dispatch } = this.props;
dispatch({
type: 'user/fetchCurrent',
});
}
render() {
const {
index: { name },
} = this.props;
return <div className={styles.userCenter}>Hello {name}</div>;
}
}

export default Page;
Empty file.
32 changes: 32 additions & 0 deletions initapp/src/pages/index/b.1.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { connect } from 'dva';
import React, { Component } from 'react';

import { IndexModelState, ConnectProps } from '@/models/connect';
import { Button } from 'antd';
import styles from './index.less';
const a = '';
interface PageProps extends ConnectProps {
index: IndexModelState;
}

interface PageState {}

@connect(({ index }) => ({ index }))
class Page extends Component<PageProps, PageState> {
state: PageState = {};

componentDidMount() {
const { dispatch } = this.props;
dispatch({
type: 'user/fetchCurrent',
});
}
render() {
const {
index: { name },
} = this.props;
return <div className={styles.userCenter}>Hellobbbbbb {name}</div>;
}
}

export default Page;
9 changes: 8 additions & 1 deletion packages/alita/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import path from 'path';
const defaultOptions = {
history: 'hash',
treeShaking: true,
umi: { dva: true, antd: true },
umi: {
dva: true, antd: true, routes: {
// 规定只有index文件会被识别成路由
exclude: [
/(?<![\s\S]*index\$?\.(js|jsx|ts|tsx)?)$/
]
},
},
menu: {
build: path.resolve('.', './src/menus.json'),
}
Expand Down

0 comments on commit 3c2d572

Please sign in to comment.