简体   繁体   English

NextJS 错误页面自定义 CSS 不工作

[英]NextJS Error Page Custom CSS is Not Working

I generate 500 page in _error.js, when get errorCode ise 500 I want return special 500 page import.我在 _error.js 中生成 500 页,当得到 errorCode ise 500 我想返回特殊的 500 页导入。

There is no problem for my code, when user get 500 is saw my special 500 page, but css not working?我的代码没有问题,当用户获得 500 时看到我的特殊 500 页面,但 css 不起作用?

CSS is come in tag but not working CSS 有标签但不工作

Here is my _error.js code:这是我的 _error.js 代码:

import React from 'react'
import Error from 'next/error'
import PageInternal from './500'

const MyError = ({ statusCode, hasGetInitialPropsRun, err }) => {

  return <Error statusCode={statusCode} />

  function Error({ statusCode }) {
    if (statusCode === 500) return <PageInternal />
  }
}

MyError.getInitialProps = async ({ res, err, asPath }) => {
  const errorInitialProps = await Error.getInitialProps({ res, err })
  const statusCode = res ? res.statusCode : err ? err.statusCode : 404
.... bla
}

CSS is not working, also JSX not working. CSS 不工作,JSX 也不工作。 I don't understand我不明白

My custom 500 Component Pic我的自定义 500 组件图片

CSS not loading? CSS 未加载? Pic图片

My 500 component:我的 500 组件:

import React from 'react'
import DefaultLayout from 'components/layouts/default'
import './style.scss'

const PageInternal = (props) => {

  return (
    <DefaultLayout
      title="Problem"
      {...props}
    >
      <div className="page-internal">
        <div className="internal-image">500</div>
        <p>
          Technical Problems
        </p>
        <a className="btn btn-default btn-lg">Refresh Page</a>
      </div>
    </DefaultLayout>
  )
}
export default PageInternal

if you use styles.component, you need update Next.js to 10+ version.如果您使用 styles.component,您需要将 Next.js 更新到 10+ 版本。 More details here https://github.com/vercel/next.js/issues/16931更多细节在这里https://github.com/vercel/next.js/issues/16931

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM