我是使用前端和反应 js 的新手。我在我的应用程序中安装了一个模板。index.html 文件包含 css 的所有链接和路径
index.html
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
{ all the css links and scripts goes here}
</body>
</html>
这是我的 app.js 文件。这里我提到了我的上层路线
import logo from './logo.svg';
import './App.css';
import Layout from '../src/Components/Layout/Layout'
import LoginScreen from './Components/Login/LoginScreen'
import { BrowserRouter as Router, Route } from "react-router-dom";
function App() {
return (
<div className="App">
<Router>
<Route path="/pages" component={Layout}/>
<Route path="/login" component={LoginScreen} exact />
</Router>
</div>
);
}
export default App;
这是我的布局组件,由所有屏幕组件(较低级别的路线)组成
import React from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";
import css_class from "./Layout.module.css";
import Navbar from '../Navbar/Navbar';
import TopNavbar from '../TopNavbar/TopNavbar'
import Home from '../Home/Home'
import About from '../About/About'
import OurProject from '../OurProject/OurProject'
function Layout() {
return (
<body>
<Router>
<TopNavbar/>
<div class="pcoded-main-container">
<div class="pcoded-wrapper">
<nav class="pcoded-navbar">
<div class="sidebar_toggle"><a href="#"><i class="icon-close icons"></i></a>
</div>
<div class="pcoded-inner-navbar main-menu">
<div class="">
<div class="main-menu-header">
<img class="img-80 img-radius" style={{height:'7.9em'}}
src="/divylogo.png" alt="User-Profile-Image" />
</div>
<div class="main-menu-content">
<ul>
<li class="more-details">
<a href="user-profile.html"><i class="ti-user"></i>View
Profile</a>
<a href="#!"><i class="ti-settings"></i>Settings</a>
</li>
</ul>
</div>
</div>
<Navbar />
</div>
</nav>
<div class="pcoded-inner-content">
<div class="main-body">
<div class="page-wrapper">
<div class="page-body">
{/* ##################################### */}
<Route path="/" component={Home} exact />
<Route path="/crausal/:id/edit" component={HomeSec2Sub} />
<Route path="/about" component={About} />
<Route path="/ourproject" component={OurProject} />
<Route path="/projects" component={Projects} />
{/* ##################################### */}
</div>
</div>
</div>
<div id="styleSelector">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="assets/js/jquery.mCustomScrollbar.concat.min.js "></script>
<script src="assets/js/pcoded.min.js"></script>
<script src="assets/js/vertical/vertical-layout.min.js "></script>
<script type="text/javascript" src="assets/js/script.js "></script>
</Router>
</body>
);
}
export default Layout;
但不知何故,我的页面,即布局组件没有得到任何 CSS。在我的 app.js 文件中,如果我将 Layout 组件的路由从 (pages/) 更改为 (/),那么一切正常。但是,如果我使用 (pages/ as route) 我不会为布局组件中提到的子路由获得任何 CSS。