1. 程式人生 > >react link引入外部css樣式的坑

react link引入外部css樣式的坑

剛開始的程式碼是這樣的,使用react router4.x寫的demo路由跳轉後,頁面的沒有渲染,是因為沒有引入外部css檔案(或者說引入外部檔案路徑錯誤)

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="theme-color" content="#000000">
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
    <title>React App</title>
    
    <link rel="stylesheet" href="./css/bootstrap.css">
</head> <body> <noscript> You need to enable JavaScript to run this app. </noscript> <div id="root"></div> </body> </html>

 將上面程式碼(紅色部分)的點去掉就可以了,如下所示

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="theme-color" content="#000000">
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
    <title>React App</title>
    
    <link rel="stylesheet" href="/css/bootstrap.css">
</head> <body> <noscript> You need to enable JavaScript to run this app. </noscript> <div id="root"></div> </body> </html>