样式添加 #760

Merged
Eeeros merged 3 commits from Eeeros/forgeplus-react:gitlink_ssr_test into gitlink_ssr 2024-07-15 09:11:42 +08:00
4 changed files with 11 additions and 2 deletions

1
public/css/detail.css Normal file

File diff suppressed because one or more lines are too long

View File

@ -78,8 +78,12 @@ export const render = async (req,res)=>{
script.setAttribute('id', 'initState')
}
script.textContent = `window.__initState__ = ${ JSON.stringify(store.getState()) }`
const styleNode = domObj.window.document.createElement('style')
styleNode.type = 'text/css'
// styleNode.innerHTML = `${ [...css].join('') }`
styleNode.innerHTML = detailCss
domObj.window.document.head.appendChild(script);
domObj.window.document.head.appendChild(styleNode);
}

View File

@ -6,6 +6,8 @@ import axios from "axios";
const { JSDOM } = jsdom;
const html = fs.readFileSync(path.join(path.resolve('./build'),'index.html'),'utf-8');
// 压缩的项目详情页需要的css
const css = fs.readFileSync(path.join(path.resolve('./build/css'),'detail.css'),'utf-8');
const { window } = new JSDOM(html);
const $ = require( "jquery" )( window )
@ -14,6 +16,8 @@ global.window = window;
global.document = window.document;
global.navigator = window.navigator;
global.localStorage = {}
// 全局缓存css
global.detailCss = css
export const getDomObj = () => {
return new JSDOM(html)

View File

@ -96,7 +96,7 @@ export function initAxiosInterceptors(props) {
if (response.data.status === 404) {
let responseURL = (response && response.request) ? response.request.responseURL:'';
// 组织和个人的拥有情况404不跳转
if (responseURL.indexOf('/api/users/') === -1 && responseURL.indexOf('/api/organizations/') === -1 ) {
if (responseURL && responseURL.indexOf('/api/users/') === -1 && responseURL.indexOf('/api/organizations/') === -1 ) {
// 邀请页面不进行404跳转
if( window.location.pathname.includes('/invite') && (responseURL.includes('/simple.json')||responseURL.includes('/detail.json')||responseURL.includes('/menu_list.json'))){
}else{