提交 0b4cc019 authored 作者: vipcxj's avatar vipcxj

fix router error

上级 6db9f117
......@@ -30,5 +30,20 @@ module.exports = (baseConfig, env) => {
],
});
config.module.rules = config.module.rules.map(rule => {
if (`${rule.test}` === `${/\.md$/}`) {
return {
test: /\.md$/,
use: [
require.resolve('html-loader'),
require.resolve('highlight-loader'),
require.resolve('markdown-loader'),
],
}
} else {
return rule;
}
});
return config;
};
......@@ -9624,6 +9624,148 @@
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=",
"dev": true
},
"highlight-loader": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/highlight-loader/-/highlight-loader-0.7.2.tgz",
"integrity": "sha1-YnGlYXzw3D4dAXdBZ+qXXXrOWp0=",
"dev": true,
"requires": {
"cheerio": "0.19.0",
"he": "0.5.0",
"highlight.js": "9.12.0",
"loader-utils": "0.2.17"
},
"dependencies": {
"cheerio": {
"version": "0.19.0",
"resolved": "https://registry.npmjs.org/cheerio/-/cheerio-0.19.0.tgz",
"integrity": "sha1-dy5wFfLuKZZQltcepBdbdas1SSU=",
"dev": true,
"requires": {
"css-select": "1.0.0",
"dom-serializer": "0.1.0",
"entities": "1.1.1",
"htmlparser2": "3.8.3",
"lodash": "3.10.1"
}
},
"css-select": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/css-select/-/css-select-1.0.0.tgz",
"integrity": "sha1-sRIcpRhI3SZOIkTQWM7iVN7rRLA=",
"dev": true,
"requires": {
"boolbase": "1.0.0",
"css-what": "1.0.0",
"domutils": "1.4.3",
"nth-check": "1.0.1"
}
},
"css-what": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/css-what/-/css-what-1.0.0.tgz",
"integrity": "sha1-18wt9FGAZm+Z0rFEYmOUaeAPc2w=",
"dev": true
},
"domhandler": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz",
"integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=",
"dev": true,
"requires": {
"domelementtype": "1.3.0"
}
},
"domutils": {
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/domutils/-/domutils-1.4.3.tgz",
"integrity": "sha1-CGVRN5bGswYDGFDhdVFrr4C3Km8=",
"dev": true,
"requires": {
"domelementtype": "1.3.0"
}
},
"he": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/he/-/he-0.5.0.tgz",
"integrity": "sha1-LAX/rvkLaOhg8/0rVO9YCYknfuI=",
"dev": true
},
"htmlparser2": {
"version": "3.8.3",
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz",
"integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=",
"dev": true,
"requires": {
"domelementtype": "1.3.0",
"domhandler": "2.3.0",
"domutils": "1.5.1",
"entities": "1.0.0",
"readable-stream": "1.1.14"
},
"dependencies": {
"domutils": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz",
"integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=",
"dev": true,
"requires": {
"dom-serializer": "0.1.0",
"domelementtype": "1.3.0"
}
},
"entities": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz",
"integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=",
"dev": true
}
}
},
"loader-utils": {
"version": "0.2.17",
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-0.2.17.tgz",
"integrity": "sha1-+G5jdNQyBabmxg6RlvF8Apm/s0g=",
"dev": true,
"requires": {
"big.js": "3.2.0",
"emojis-list": "2.1.0",
"json5": "0.5.1",
"object-assign": "4.1.1"
}
},
"lodash": {
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz",
"integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=",
"dev": true
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"dev": true,
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "0.0.1",
"string_decoder": "0.10.31"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
}
}
},
"highlight.js": {
"version": "9.12.0",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.12.0.tgz",
"integrity": "sha1-5tnb5Xy+/mB1HwKvM2GVhwyQwB4=",
"dev": true
},
"history": {
"version": "4.7.2",
"resolved": "https://registry.npmjs.org/history/-/history-4.7.2.tgz",
......@@ -16403,9 +16545,9 @@
}
},
"react-router-4-compat": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/react-router-4-compat/-/react-router-4-compat-0.1.2.tgz",
"integrity": "sha512-gy5eE4qfaagRT35ouOqZ6QKW8DOvQ6ykGOcLqmBESnob2XmQDfJjKCvynt+TDwRH1RR47thGjaAGu+sp+WvSEQ==",
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/react-router-4-compat/-/react-router-4-compat-0.1.4.tgz",
"integrity": "sha512-ZDsQsrIf4yohd/wSNz5s9E9mh+PdgOrymIY28Xqz+cWWJR6x8S9OCeL41kutWIwfzvp481akbgasnegPw+inbQ==",
"requires": {
"hoist-non-react-statics": "2.5.0",
"invariant": "2.2.4",
......
......@@ -30,7 +30,7 @@
"react-async-wrapper": "^0.0.7",
"react-dom": "^16.2.0",
"react-json-view": "^1.11.4",
"react-router-4-compat": "^0.1.2",
"react-router-4-compat": "^0.1.4",
"resolve-pathname": "^2.1.0",
"uuid": "^3.1.0",
"word-wrap": "^1.2.3",
......@@ -51,13 +51,15 @@
"cross-env": "^5.1.3",
"ejs-loader": "^0.3.1",
"enzyme": "^3.3.0",
"jest": "^22.4.2",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-lodash-fp": "^2.1.3",
"highlight-loader": "^0.7.2",
"http-proxy-middleware": "^0.17.4",
"jest": "^22.4.2",
"jsdom": "^11.0.0",
"lodash-webpack-plugin": "^0.11.4",
"markdown-loader": "^2.0.2",
"mockjs": "^1.0.1-beta3",
"path": "^0.12.7",
"react-test-renderer": "^16.2.0",
......
import { makePath } from '../../utils/helper';
const route = (routes) => {
const Wrapper = ({ children }) => {
return children;
return children || null;
};
Wrapper.route = {
...routes,
......@@ -8,7 +10,7 @@ const route = (routes) => {
onEnter(nextState, replace) {
if (routes && routes.childRoutes && routes.childRoutes.length > 0) {
const index = routes.childRoutes[0];
replace(`${nextState.location.pathname}/${index.path}`);
replace(makePath(nextState.match.url, index.path));
}
},
},
......
/* eslint-disable */
export default [/* {
export default [/*{
name: 'test-menu',
showName: '测试',
modules: [{
name: 'test-module',
showName: '测试',
layout: {
route: 'test',
route: 'task',
},
}],
}*/];
......@@ -92,8 +92,9 @@ const createRoutes = async (app, modules, groups, basePath) => {
if (layout.route) {
const modelBundle = await import(`./models/main/modules/${layout.route}`);
registerModel(app, modelBundle.default);
const routeBundle = await import(`./routes/main/modules/${layout.route}`);
route.component = routeBundle.default;
let routeBundle = await import(`./routes/main/modules/${layout.route}`);
routeBundle = routeBundle.default || routeBundle;
route.component = routeBundle;
if (routeBundle.route) {
for (const key in routeBundle.route) {
// noinspection JSUnfilteredForInLoop
......
import createBrowserHistory from 'history/createBrowserHistory';
import resolvePathname from 'resolve-pathname';
import isString from 'lodash/isString';
import config from '../utils/config';
const { contextPath } = config;
const makePath = (base, path, withContext = true) => {
if (path.startsWith('/')) {
return withContext ? `${contextPath}${path}` : path;
}
const basePath = base.endsWith('/') ? base : `${base}/`;
return resolvePathname(path, basePath);
};
import { makePath } from '../utils/helper';
const processPath = (base, path, withContext = true) => {
if (isString(path)) {
......@@ -42,6 +31,7 @@ export const getLocation = () => {
};
export const createHistory = (...args) => {
history = createBrowserHistory(...args);
// noinspection JSUnresolvedFunction
history.listen((loc) => {
location = { ...loc };
});
......@@ -91,23 +81,23 @@ const getThisBase = (theThis) => {
export const thisPush = (theThis, pathOrLoc, withContext = true) => {
checkThis(theThis);
const route = processPath(getThisBase(theThis), pathOrLoc, withContext);
return theThis.props.router.push(route);
return theThis.props.router.history.push(route);
};
export const thisReplace = (theThis, pathOrLoc, withContext = true) => {
checkThis(theThis);
const route = processPath(getThisBase(theThis), pathOrLoc, withContext);
return theThis.props.router.replace(route);
return theThis.props.router.history.replace(route);
};
export const thisGo = (theThis, n) => {
checkThis(theThis);
return theThis.props.router.go(n);
return theThis.props.router.history.go(n);
};
export const thisGoBack = (theThis) => {
checkThis(theThis);
return theThis.props.router.goBack();
return theThis.props.router.history.goBack();
};
export const thisGoForward = (theThis) => {
......
......@@ -2,6 +2,7 @@ import moment from 'moment';
import pickBy from 'lodash/pickBy';
import negate from 'lodash/negate';
import isUndefined from 'lodash/isUndefined';
import resolvePathname from 'resolve-pathname';
import { createJSEncrypt } from './jsencrypt';
import config from './config';
......@@ -56,6 +57,14 @@ export function locationOrigin(withContext = true) {
return `${location.protocol}//${location.hostname}${location.port ? ':' + location.port : ''}${withContext ? contextPath : ''}`; // eslint-disable-line
}
export const makePath = (base, path, withContext = true) => {
if (path.startsWith('/')) {
return withContext ? `${contextPath}${path}` : path;
}
const basePath = base.endsWith('/') ? base : `${base}/`;
return resolvePathname(path, basePath);
};
export function currentPath() {
let path = location.pathname; // eslint-disable-line
if (!path) {
......
......@@ -14,6 +14,7 @@ import UCA from '../src/components/uca';
import dva from './lib/dva';
import lazy from './lib/lazy';
import loginIt from './lib/login';
import testMd from './test.md';
storiesOf('a', module)
.add('1', () => {
......@@ -80,3 +81,9 @@ storiesOf('table-input', module)
const Example = Form.create()(Temp);
return <Example />;
});
storiesOf('markdown', module)
.add('test', () => (<div dangerouslySetInnerHTML={{
__html: testMd,
}}
/>));
markdown-loader
===============
markdown-loader for webpack using [marked](https://github.com/chjj/marked).
[![](https://img.shields.io/npm/v/markdown-loader.svg)](https://www.npmjs.com/package/markdown-loader)
[![](https://img.shields.io/npm/dm/markdown-loader.svg)](https://www.npmjs.com/package/markdown-loader)
[![Dependency Status](https://david-dm.org/peerigon/markdown-loader.svg)](https://david-dm.org/peerigon/markdown-loader)
[![Build Status](https://travis-ci.org/peerigon/markdown-loader.svg?branch=master)](https://travis-ci.org/peerigon/markdown-loader)
## Installation
`npm install markdown-loader`
## Usage
Since marked's output is HTML, it's best served in conjunction with the [html-loader](https://github.com/webpack/html-loader).
### Webpack 2
```javascript
{
module: {
rules: [{
test: /\.md$/,
use: [
{
loader: "html-loader"
},
{
loader: "markdown-loader",
options: {
/* your options here */
}
}
]
}]
}
}
```
### Options
Simply pass your marked [options](https://github.com/chjj/marked#options-1) as shown above.
In order to specify [custom renderers](https://github.com/peerigon/markdown-loader/issues/5), simply set the `options.renderer`-option on your webpack options.
```javascript
// webpack.config.js
const marked = require("marked");
const renderer = new marked.Renderer();
return {
module: {
rules: [{
test: /\.md$/,
use: [
{
loader: "html-loader"
},
{
loader: "markdown-loader",
options: {
pedantic: true,
renderer
}
}
]
}]
}
}
```
## License
MIT (http://www.opensource.org/licenses/mit-license.php)
## Sponsors
[<img src="https://assets.peerigon.com/peerigon/logo/peerigon-logo-flat-spinat.png" width="150" />](https://peerigon.com)
......@@ -45,6 +45,14 @@ module.exports = function webpack(config) {
test: /\.ejs$/,
loader: 'ejs-loader',
});
config.module.rules.push({
test: /\.md$/,
use: [
'html-loader',
'highlight-loader',
'markdown-loader',
],
});
let cleanedConfig = omit(config, 'plugins');
cleanedConfig.resolve = omit(cleanedConfig.resolve, 'plugins');
cleanedConfig = pickDeep(cleanedConfig, v => !isFunction(v) && !isUndefined(v));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论