Next.js - import css file does not work

后端 未结 6 755
北荒
北荒 2021-02-18 22:31

I am creating a project with react, redux and next.js, and want to import CSS files in js.

I followed instructions in next.js/#css and next-css, but find out that CSS st

6条回答
  •  爱一瞬间的悲伤
    2021-02-18 23:13

    As Zeit said :

    1. Create a /static folder at the same level the /pages folder.
    2. In that folder put your .css files
    3. In your page components import Head and add a to your CSS.

    import Head from 'next/head'
    
    function IndexPage() {
      return (
        
    My page title

    Hello world!

    ) } export default IndexPage

    And that's it, this way Next.js should render the link tag in the head of the page and the browser will download the CSS and apply it.

    Thanks Sergiodxa at Github for this clear solution.

提交回复
热议问题