Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

How can a React project work with multiple HTML files?

ppowell777

Well-Known Coder
Currently I have a React project that, by default, goes to /public/index.html, serves up /src/index.js, and the homepage is displayed just fine.

However, I will also need to do the same to /public/guide/index.html, to /public/login/index.html, /public/questions/index.html, etc. I have static HTML content in /public, /public/guide, /public/login, etc. with the "contents" DOM in the <BODY> tag emptied out, filled by a select React component. This works just fine with the homepage, however, the Guide page only shows the static HTML shell and no contents from the Guide React component.

I am trying to work my architecture around this article on Stack Overflow, but nothing is happening beyond the homepage.

index.js:

JavaScript:
import React from "react";
import ReactDOM from "react-dom/client";
import { BrowserRouter } from "react-router-dom";
import App from "./components/App";

const root = ReactDOM.createRoot(document.getElementById('contents'));
root.render(
    <React.StrictMode>
      <BrowserRouter>
        <App />
      </BrowserRouter>
    </React.StrictMode>
);

App.js:

JavaScript:
import { Routes, Route } from "react-router-dom";
import HomePage from "./Apps/homepage.js";
import GuidePage from "./Apps/loginpage.js";

const App = () => {
    return (
        <Routes>
          <Route exact path="/" element={<HomePage />} />
          <Route exact path="/guide/" element={<GuidePage />} />
        </Routes>
    );
};

export default App;

I do not have nor know how to find or work with webpack.config.js to handle multiple HTML files, so I will need a lot of handholding.

Can someone show me exactly where I would need to go to learn how to do this effectively?

Thanks
 
Back
Top Bottom