Merge branch 'feature_router' of https://git.trustie.net/Gitlink/forgeplus-react into feature_router
This commit is contained in:
commit
bf3f404238
|
@ -19,7 +19,8 @@ const getClientEnvironment = require("./env");
|
||||||
|
|
||||||
let publicPath = "/react/build/";
|
let publicPath = "/react/build/";
|
||||||
const publicUrl = publicPath.slice(0, -1);
|
const publicUrl = publicPath.slice(0, -1);
|
||||||
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== "false";
|
// const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== "false";
|
||||||
|
const shouldUseSourceMap = process.env.NODE_ENV !== "production";
|
||||||
const env = getClientEnvironment(publicPath);
|
const env = getClientEnvironment(publicPath);
|
||||||
|
|
||||||
// This is the production configuration.
|
// This is the production configuration.
|
||||||
|
@ -54,7 +55,8 @@ module.exports = {
|
||||||
},
|
},
|
||||||
bail: true,
|
bail: true,
|
||||||
mode: "production",
|
mode: "production",
|
||||||
devtool: false, //测试版
|
// devtool: false, //测试版
|
||||||
|
devtool: shouldUseSourceMap?'source-map':false,
|
||||||
entry: [require.resolve("./polyfills"), paths.appIndexJs],
|
entry: [require.resolve("./polyfills"), paths.appIndexJs],
|
||||||
output: {
|
output: {
|
||||||
path: paths.appBuild,
|
path: paths.appBuild,
|
||||||
|
|
33
src/App.js
33
src/App.js
|
@ -114,13 +114,22 @@ class App extends Component {
|
||||||
this.unlisten = this.props.history.listen((location) => {
|
this.unlisten = this.props.history.listen((location) => {
|
||||||
let newPathname = location.pathname.split('/')[1];
|
let newPathname = location.pathname.split('/')[1];
|
||||||
if(this.state.pathName!==newPathname){
|
if(this.state.pathName!==newPathname){
|
||||||
|
this.setState({pathType:''});
|
||||||
newPathname && this.getPathnameType(newPathname);
|
newPathname && this.getPathnameType(newPathname);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldComponentUpdate(nextProps, nextState) {
|
||||||
|
if (nextProps.location.pathname.split('/')[1] !== this.props.location.pathname.split('/')[1] && nextState.pathType === this.state.pathType) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getPathnameType = (pathname) => {
|
getPathnameType = (pathname) => {
|
||||||
let keyWord = ["Gitlink", "Trustie", "explore", "settings", "setting", "CCF", "mulan", "wiki", "issues", "setting", "trending", "code", "projects", "pulls", "mine", "login", "register", "email", "export", "nopage", "404", "403", "500", "501"];
|
let keyWord = ["Gitlink", "Trustie", "explore", "settings", "setting", "CCF", "mulan", "wiki", "issues", "setting", "trending", "code", "projects", "pulls", "mine", "login", "register", "email", "export", "nopage", "404", "403", "500", "501", "search"];
|
||||||
if (!keyWord.includes(pathname)) {
|
if (!keyWord.includes(pathname)) {
|
||||||
let url = `/owners/${pathname}.json`;
|
let url = `/owners/${pathname}.json`;
|
||||||
axios.get(url).then((response) => {
|
axios.get(url).then((response) => {
|
||||||
|
@ -308,6 +317,16 @@ class App extends Component {
|
||||||
}>
|
}>
|
||||||
</Route> */}
|
</Route> */}
|
||||||
|
|
||||||
|
{/*项目*/}
|
||||||
|
<Route
|
||||||
|
path={"/projects"}
|
||||||
|
render={
|
||||||
|
(props) => {
|
||||||
|
return (<Projects {...this.props} {...props} {...this.state} />)
|
||||||
|
}
|
||||||
|
}>
|
||||||
|
</Route>
|
||||||
|
|
||||||
{/* 判断为用户/组织,并进入对应页面 */}
|
{/* 判断为用户/组织,并进入对应页面 */}
|
||||||
{
|
{
|
||||||
pathType === 'User' ?
|
pathType === 'User' ?
|
||||||
|
@ -335,16 +354,7 @@ class App extends Component {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
{/*项目*/}
|
|
||||||
<Route
|
|
||||||
path={"/projects"}
|
|
||||||
render={
|
|
||||||
(props) => {
|
|
||||||
return (<Projects {...this.props} {...props} {...this.state} />)
|
|
||||||
}
|
|
||||||
}>
|
|
||||||
</Route>
|
|
||||||
|
|
||||||
{/* 组织 */}
|
{/* 组织 */}
|
||||||
<Route path={"/organize"}
|
<Route path={"/organize"}
|
||||||
render={
|
render={
|
||||||
|
@ -355,7 +365,6 @@ class App extends Component {
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
{/* 个人主页 */}
|
{/* 个人主页 */}
|
||||||
|
|
||||||
<Route path="/:username"
|
<Route path="/:username"
|
||||||
render={
|
render={
|
||||||
(props) => {
|
(props) => {
|
||||||
|
|
|
@ -86,7 +86,7 @@ export function initAxiosInterceptors(props) {
|
||||||
|
|
||||||
if (response.data.status === 404) {
|
if (response.data.status === 404) {
|
||||||
let responseURL = response.request ? response.request.responseURL:'';
|
let responseURL = response.request ? response.request.responseURL:'';
|
||||||
if (responseURL.indexOf('/api/users/') === -1 && responseURL.indexOf('/api/organizations/') === -1) {
|
if (responseURL.indexOf('/api/users/') === -1 && responseURL.indexOf('/api/organizations/') === -1 && responseURL.indexOf('/api/owners/') === -1) {
|
||||||
locationurl('/nopage');
|
locationurl('/nopage');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,11 @@ const ProjectIndex = Loadable({
|
||||||
loading: Loading,
|
loading: Loading,
|
||||||
});
|
});
|
||||||
|
|
||||||
const ProjectDetail = Loadable({
|
// 项目详情放在用户和组织下作为二级菜单存在
|
||||||
loader: () => import("./Main/Detail"),
|
// const ProjectDetail = Loadable({
|
||||||
loading: Loading,
|
// loader: () => import("./Main/Detail"),
|
||||||
});
|
// loading: Loading,
|
||||||
|
// });
|
||||||
|
|
||||||
class Index extends Component {
|
class Index extends Component {
|
||||||
|
|
||||||
|
@ -40,35 +41,35 @@ class Index extends Component {
|
||||||
<div className="newMain clearfix">
|
<div className="newMain clearfix">
|
||||||
<Switch {...this.props}>
|
<Switch {...this.props}>
|
||||||
<Route
|
<Route
|
||||||
path="/:projectsType/new/:OIdentifier"
|
path="/projects/:projectsType/new/:OIdentifier"
|
||||||
render={(props) => (
|
render={(props) => (
|
||||||
<ProjectNew {...this.props} {...props} />
|
<ProjectNew {...this.props} {...props} />
|
||||||
)}
|
)}
|
||||||
></Route>
|
></Route>
|
||||||
<Route
|
<Route
|
||||||
path="/:projectsType/new"
|
path="/projects/:projectsType/new"
|
||||||
render={(props) => (
|
render={(props) => (
|
||||||
<ProjectNew {...this.props} {...props} />
|
<ProjectNew {...this.props} {...props} />
|
||||||
)}
|
)}
|
||||||
></Route>
|
></Route>
|
||||||
<Route
|
<Route
|
||||||
path="/projects/new"
|
path="/projects/mirror/new"
|
||||||
render={(props) => (
|
render={(props) => (
|
||||||
<ProjectNew {...this.props} {...props} />
|
<ProjectNew {...this.props} {...props} />
|
||||||
)}
|
)}
|
||||||
></Route>
|
></Route>
|
||||||
<Route
|
{/* <Route
|
||||||
path="/:owner/:projectsId"
|
path="/:owner/:projectsId"
|
||||||
render={(props) => (
|
render={(props) => (
|
||||||
<ProjectDetail {...this.props} {...props} />
|
<ProjectDetail {...this.props} {...props} />
|
||||||
)}
|
)}
|
||||||
></Route>
|
></Route> */}
|
||||||
{/* <Route
|
<Route
|
||||||
path="/projects"
|
path="/explore"
|
||||||
render={(props) => (
|
render={(props) => (
|
||||||
<ProjectIndex {...this.props} {...props} />
|
<ProjectIndex {...this.props} {...props} />
|
||||||
)}
|
)}
|
||||||
></Route> */}
|
></Route>
|
||||||
<Route
|
<Route
|
||||||
path="/"
|
path="/"
|
||||||
render={(props) => (
|
render={(props) => (
|
||||||
|
@ -80,16 +81,16 @@ class Index extends Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// export default withRouter(
|
|
||||||
// ImageLayerOfCommentHOC({
|
|
||||||
// imgSelector: ".imageLayerParent img, .imageLayerParent .imageTarget",
|
|
||||||
// parentSelector: ".newMain",
|
|
||||||
// })(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC(Index))))
|
|
||||||
// );
|
|
||||||
|
|
||||||
export default withRouter(
|
export default withRouter(
|
||||||
ImageLayerOfCommentHOC({
|
ImageLayerOfCommentHOC({
|
||||||
imgSelector: ".imageLayerParent img, .imageLayerParent .imageTarget",
|
imgSelector: ".imageLayerParent img, .imageLayerParent .imageTarget",
|
||||||
parentSelector: ".newMain",
|
parentSelector: ".newMain",
|
||||||
})(Index)
|
})(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC(Index))))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// export default withRouter(
|
||||||
|
// ImageLayerOfCommentHOC({
|
||||||
|
// imgSelector: ".imageLayerParent img, .imageLayerParent .imageTarget",
|
||||||
|
// parentSelector: ".newMain",
|
||||||
|
// })(Index)
|
||||||
|
// );
|
||||||
|
|
|
@ -26,6 +26,11 @@ const SubDetailIndex = Loadable({
|
||||||
loader: () => import("./Sub/SubDetail"),
|
loader: () => import("./Sub/SubDetail"),
|
||||||
loading: Loading,
|
loading: Loading,
|
||||||
});
|
});
|
||||||
|
// forge项目详情
|
||||||
|
const ProjectDetail = Loadable({
|
||||||
|
loader: () => import("../Main/Detail"),
|
||||||
|
loading: Loading,
|
||||||
|
});
|
||||||
export default withRouter(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC(
|
export default withRouter(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC(
|
||||||
((props)=>{
|
((props)=>{
|
||||||
return (
|
return (
|
||||||
|
@ -66,6 +71,15 @@ export default withRouter(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC(
|
||||||
return <New {...props} {...p}/>
|
return <New {...props} {...p}/>
|
||||||
}}
|
}}
|
||||||
></Route>
|
></Route>
|
||||||
|
|
||||||
|
{/* 组织下的项目详情 */}
|
||||||
|
<Route
|
||||||
|
path="/:owner/:projectsId"
|
||||||
|
render={(p) => (
|
||||||
|
<ProjectDetail {...props} {...p} />
|
||||||
|
)}
|
||||||
|
></Route>
|
||||||
|
|
||||||
{/* 组织详情(包含组织设置) */}
|
{/* 组织详情(包含组织设置) */}
|
||||||
<Route
|
<Route
|
||||||
path="/:OIdentifier"
|
path="/:OIdentifier"
|
||||||
|
|
|
@ -11,13 +11,18 @@ const Infos = Loadable({
|
||||||
loading: Loading,
|
loading: Loading,
|
||||||
});
|
});
|
||||||
//forge项目
|
//forge项目
|
||||||
const Projects = Loadable({
|
// const Projects = Loadable({
|
||||||
loader: () => import('../Index'),
|
// loader: () => import('../Index'),
|
||||||
|
// loading: Loading,
|
||||||
|
// })
|
||||||
|
// forge项目详情
|
||||||
|
const ProjectDetail = Loadable({
|
||||||
|
loader: () => import("../Main/Detail"),
|
||||||
loading: Loading,
|
loading: Loading,
|
||||||
})
|
});
|
||||||
export default withRouter(
|
export default withRouter(
|
||||||
(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC((props) => {
|
(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC((props) => {
|
||||||
console.log(props.location.pathname);
|
// 个人中心新增的二级目录都需在此添加一次。将项目放组织和个人名下后,此处根据二级目录作判断,
|
||||||
let secondRouter = '';
|
let secondRouter = '';
|
||||||
if (props.location.pathname) {
|
if (props.location.pathname) {
|
||||||
secondRouter = props.location.pathname.split('/')[2];
|
secondRouter = props.location.pathname.split('/')[2];
|
||||||
|
@ -25,13 +30,26 @@ export default withRouter(
|
||||||
let userRouterArr = ['statistics', 'projects', 'notice', 'devops', 'organizes', 'info', 'watchers', 'fan_users', 'password'];
|
let userRouterArr = ['statistics', 'projects', 'notice', 'devops', 'organizes', 'info', 'watchers', 'fan_users', 'password'];
|
||||||
return (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route
|
{/* <Route
|
||||||
path="/:username"
|
path="/:username"
|
||||||
render={(p) => (
|
render={(p) => (
|
||||||
secondRouter && (!userRouterArr.includes(secondRouter)) ?
|
secondRouter && (!userRouterArr.includes(secondRouter)) ?
|
||||||
<Projects {...props} {...p} /> : <Infos {...props} {...p} />
|
<ProjectDetail {...props} {...p} /> : <Infos {...props} {...p} />
|
||||||
)}
|
)}
|
||||||
></Route>
|
></Route> */}
|
||||||
|
|
||||||
|
{secondRouter && (!userRouterArr.includes(secondRouter)) ? <Route
|
||||||
|
path="/:owner/:projectsId"
|
||||||
|
render={(p) => (
|
||||||
|
<ProjectDetail {...props} {...p} />
|
||||||
|
)}
|
||||||
|
></Route> : <Route
|
||||||
|
path="/:username"
|
||||||
|
render={(p) => (
|
||||||
|
<Infos {...props} {...p} />
|
||||||
|
)}
|
||||||
|
></Route>}
|
||||||
|
|
||||||
</Switch>
|
</Switch>
|
||||||
)
|
)
|
||||||
}))))
|
}))))
|
||||||
|
|
Loading…
Reference in New Issue