Merge pull request '匹配其他没有完全ssr的页面' (#705) from Eeeros/forgeplus-react:gitlink_ssr_head into gitlink_ssr_head

1
This commit is contained in:
Eeeros 2024-05-06 12:52:41 +08:00
commit 95cdcd0136
5 changed files with 55 additions and 15 deletions

View File

@ -26,21 +26,25 @@ export const deepRoutes = [
{
key: "zoneNews",
path: "/zone/:deptId/newdetail/:id",
onlyHead: true,
// component: NewsDetail
},
{
key: "zone",
path: "/zone/:deptId",
onlyHead: true,
// component: Information
},
{
key: "detail",
path: "/:owner/:projectsId",
onlyHead: false,
component: Detail,
},
{
key: "owner",
path: "/:owner",
onlyHead: true,
// component: Detail,
}
]

View File

@ -56,6 +56,15 @@ export const render = async (req,res)=>{
if (_route && _route.component && _route.component.preFetch) {
// 设置服务端请求cookie
let cookies = req.headers.cookie.split(';')
for (let index = 0; index < cookies.length; index++) {
const element = cookies[index];
domObj.window.document.cookie = element
}
context = await _route.component.preFetch({
store,
match: _match,
@ -63,16 +72,20 @@ export const render = async (req,res)=>{
});
}
const content = renderToString((
<Provider store={store}>
<StaticRouter location={req.path} context={context}>
<StyleContext.Provider value={{insertCss}}>
{renderRoutes(Routes)}
{/* <Route path='/:owner/:projectsId' exact component={App}></Route> */}
</StyleContext.Provider>
</StaticRouter>
</Provider>
))
let content = undefined
if (_route && !specialRoute.includes(_match.url && _match.url.replace('/', '')) && !_route.onlyHead) {
content = renderToString((
<Provider store={store}>
<StaticRouter location={req.path} context={context}>
<StyleContext.Provider value={{insertCss}}>
{renderRoutes(Routes)}
{/* <Route path='/:owner/:projectsId' exact component={App}></Route> */}
</StyleContext.Provider>
</StaticRouter>
</Provider>
))
}
if (!content) {
// 未匹配到详情页恢复默认header

View File

@ -308,8 +308,7 @@ class Detail extends Component {
secondSync: false,
mirror_status:0
})
// this.getBanner(this.props.projectMenu)
this.getBanner()
this.getBanner(this.props.projectMenu)
let projectdata
if (this.props.defaultDetail) {
projectdata = this.props.defaultDetail

View File

@ -29,9 +29,9 @@ function ServerIndex(props){
useEffect(()=>{
// tab 3397
// if(projectDetail && projectDetail.permission === ""){
// props.history.push(`/${owner}/${projectsId}`);
// }
if(projectDetail && projectDetail.permission === ""){
props.history.push(`/${owner}/${projectsId}`);
}
}, [projectDetail])
return(

View File

@ -18,41 +18,65 @@ const axiosInstance = axios.create({
//
export async function getProjectFunc (owner, projectsId) {
const url = `${baseUrl}/${owner}/${projectsId}/simple.json`;
if (__SERVER__) {
axiosInstance.defaults.headers.cookie = domObj.window.document.cookie
}
return axiosInstance.get(url);
}
export async function getProjectDetailFunc (owner, projectsId) {
const url = `${baseUrl}/${owner}/${projectsId}/detail.json`;
if (__SERVER__) {
axiosInstance.defaults.headers.cookie = domObj.window.document.cookie
}
return axiosInstance.get(url);
}
export async function getProjectEntriesFunc (owner, projectsId, branch) {
const url = `${baseUrl}/${owner}/${projectsId}/entries.json`;
if (__SERVER__) {
axiosInstance.defaults.headers.cookie = domObj.window.document.cookie
}
return axiosInstance.get(url, {params: { ref: branch }});
}
export async function getBannerFunc (owner, projectsId) {
const url = `${baseUrl}/${owner}/${projectsId}/menu_list.json`;
if (__SERVER__) {
axiosInstance.defaults.headers.cookie = domObj.window.document.cookie
}
return axiosInstance.get(url);
}
export async function getProjectReadMe (owner, projectsId, branch) {
const url = `${baseUrl}/${owner}/${projectsId}/readme.json`;
if (__SERVER__) {
axiosInstance.defaults.headers.cookie = domObj.window.document.cookie
}
return axiosInstance.get(url, {params: { ref: branch }});
}
export async function getOwnerInfo (owner) {
const url = `${baseUrl}/owners/${owner}.json`;
if (__SERVER__) {
axiosInstance.defaults.headers.cookie = domObj.window.document.cookie
}
return axiosInstance.get(url);
}
export async function getMainInfos (deptId) {
const url = `${baseZoneUrl}/zone/open/zoneKey/${deptId}`;
if (__SERVER__) {
axiosInstance.defaults.headers.cookie = domObj.window.document.cookie
}
return axiosInstance.get(url);
}
export async function getNewsDetail (id) {
const url = `${baseZoneUrl}/cms/doc/open/${id}`;
if (__SERVER__) {
axiosInstance.defaults.headers.cookie = domObj.window.document.cookie
}
return axiosInstance.get(url);
}