diff --git a/examples/with-dva/src/models/global.js b/examples/with-dva/src/models/global.js index 2f320df760f2..658cab8d8611 100644 --- a/examples/with-dva/src/models/global.js +++ b/examples/with-dva/src/models/global.js @@ -10,4 +10,9 @@ export default { }; }, }, + effects: { + *throwError() { + throw new Error('hi error'); + }, + }, }; diff --git a/examples/with-dva/src/pages/index/page.js b/examples/with-dva/src/pages/index/page.js index be8a251172c3..775559ada87c 100644 --- a/examples/with-dva/src/pages/index/page.js +++ b/examples/with-dva/src/pages/index/page.js @@ -21,6 +21,15 @@ function App(props) { > Set Title +
Go to list.html diff --git a/examples/with-dva/src/plugins/onError.js b/examples/with-dva/src/plugins/onError.js new file mode 100644 index 000000000000..83db74cf1381 --- /dev/null +++ b/examples/with-dva/src/plugins/onError.js @@ -0,0 +1,8 @@ +import { message } from 'antd'; + +export default { + onError(err) { + err.preventDefault(); + message.error(err.message); + }, +}; diff --git a/packages/umi-plugin-dva/src/index.js b/packages/umi-plugin-dva/src/index.js index 124685bc3de9..693e1072eeb8 100644 --- a/packages/umi-plugin-dva/src/index.js +++ b/packages/umi-plugin-dva/src/index.js @@ -21,13 +21,13 @@ export default function(api) { } function getPlugins() { - const pluginPaths = globby.sync('../../plugins/*.js', { + const pluginPaths = globby.sync('plugins/*.js', { cwd: paths.absSrcPath, }); return pluginPaths .map(path => ` - app.use(require('./${path}').default); + app.use(require('../../${path}').default); `.trim(), ) .join('\r\n'); @@ -83,4 +83,12 @@ ReactDOM.render(React.createElement( }; return memo; }); + + api.register('modifyPageWatchers', ({ memo }) => { + return [ + ...memo, + join(paths.absSrcPath, 'models'), + join(paths.absSrcPath, 'plugins'), + ]; + }); }