diff --git a/src/App.js b/src/App.js index b2a4b71..20b2781 100644 --- a/src/App.js +++ b/src/App.js @@ -56,6 +56,7 @@ function jsonToArray(json) { } function App() { + const appContextPath = process.env.PUBLIC_URL + "/"; // keeps the state of the json const [data, setData] = useState(undefined); // put all books into one array. uses more memory, but search is faster and less complex @@ -89,13 +90,13 @@ function App() { async function fetchData() { try { setQueries(queryString.parse(document.location.search)); - if (queries.lang) { - if (queries.lang === "langs" || queries.lang === "subjects") { - changeParameter("lang.code", "en"); - } else { - changeParameter("lang.code", queries.lang); - } - } + if (queries.lang) { + if (queries.lang === "langs" || queries.lang === "subjects") { + changeParameter("lang.code", "en"); + } else { + changeParameter("lang.code", queries.lang); + } + } // setLoading(true); let result = await axios.get( "https://raw.githubusercontent.com/EbookFoundation/free-programming-books-search/main/fpb.json" @@ -201,7 +202,7 @@ function App() { // lang: entry.item.lang, // section: entry.item.section, // title: `List of all ${section} books in ${entry.item.lang.name}`, - // url: `/free-programming-books-search?sect=books&lang=${langCode}&file=free-programming-books-${langCode}#${section}`, + // url: `${appContextPath}?sect=books&lang=${langCode}&file=free-programming-books-${langCode}#${section}`, // samePage: true, // }, // }; @@ -253,7 +254,7 @@ function App() {

- free-programming-books + free-programming-books

diff --git a/src/components/ParsedLink.js b/src/components/ParsedLink.js index e0eb2f5..bf8a523 100644 --- a/src/components/ParsedLink.js +++ b/src/components/ParsedLink.js @@ -1,6 +1,7 @@ import React, { useState, useEffect } from "react"; function ParsedLink({ children, sect, href, id }) { + const appContextPath = process.env.PUBLIC_URL + "/"; const [folder, setFolder] = useState(null); const [file, setFile] = useState(null); @@ -29,11 +30,11 @@ function ParsedLink({ children, sect, href, id }) { }, [href]); if (folder && file) { - return {children}; + return {children}; } else if (file) { - return {children}; + return {children}; } else { // Go to the homepage when there's a bad relative URL - return {children} + return {children} } }