<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Avinash</title>
    <description>The latest articles on Forem by Avinash (@avithe1).</description>
    <link>https://forem.com/avithe1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F93201%2F78a0c8d1-1323-4936-9e40-94134776a441.jpeg</url>
      <title>Forem: Avinash</title>
      <link>https://forem.com/avithe1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/avithe1"/>
    <language>en</language>
    <item>
      <title>Deploy Vite React project with React router without 404 on Github pages</title>
      <dc:creator>Avinash</dc:creator>
      <pubDate>Thu, 09 Jan 2025 04:48:52 +0000</pubDate>
      <link>https://forem.com/avithe1/deploy-vite-react-project-with-react-router-without-404-on-github-pages-h6p</link>
      <guid>https://forem.com/avithe1/deploy-vite-react-project-with-react-router-without-404-on-github-pages-h6p</guid>
      <description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;Yes, its pretty simple to publish a Vite React project on Github pages. You will find many articles that show how this is done. I am talking about the simple publish here and not about github actions.&lt;/p&gt;

&lt;p&gt;I followed the exact steps mentioned, with every possible configuration that was explained, of course the project got published but I always got a blank page  on the live URL with &lt;strong&gt;404&lt;/strong&gt; errors when I inspected the console.&lt;/p&gt;

&lt;p&gt;My URL structure was : &lt;code&gt;https://&amp;lt;username&amp;gt;.github.io/&amp;lt;repo-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After some tinkering I realized that this issue was because I was using &lt;strong&gt;React Router&lt;/strong&gt; in the project. The fix to this issue, I had to set up the base URL in two places.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;vite.config.ts (which I was already doing following the articles)&lt;/li&gt;
&lt;li&gt;BrowserRouter &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Its the second point that took sometime to figure out. All that was needed to be done was &lt;code&gt;&amp;lt;BrowserRouter basename="/repo-name"&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This fixed the 404 issues I was facing when deploying to github pages.&lt;/p&gt;

&lt;p&gt;To summarize :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Your Vite-React project repository should be committed to github.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Take a note/copy the Repository name as it is in the Settings&amp;gt;General tab on github, I will call this &lt;code&gt;repo-name&lt;/code&gt; hereafter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;npm install gh-pages --save-dev&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;add the following to your package.json&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"homepage" : https://&amp;lt;username&amp;gt;.github.io/&amp;lt;repo-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"predeploy": "npm run build",
"deploy": "gh-pages -d dist"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;add the following to your vite.config.ts
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default defineConfig({
  base: "/repo-name", 
  plugins: [react()],
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;add the following to you BrowserRouter
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;BrowserRouter basename="/repo-name"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;run command &lt;code&gt;npm run deploy&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wait for a few seconds , check the github repository Settings&amp;gt;Pages tab if needed. &lt;/p&gt;

&lt;p&gt;Your website will be published to &lt;code&gt;https://&amp;lt;username&amp;gt;.github.io/&amp;lt;repo-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note : be careful with the forward slashes in the repo-name, I have used only &lt;code&gt;/repo-name&lt;/code&gt; and not &lt;code&gt;/repo-name/&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This also changes the localhost URL to &lt;code&gt;http://localhost:5173/repo-name&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I hope this helps anyone who is stuck with a blank page and 404 asset/js files not found in console issue when publishing a Vite React project with &lt;strong&gt;React Router&lt;/strong&gt; to Github pages. Thanks.&lt;/p&gt;

</description>
      <category>react</category>
      <category>vite</category>
      <category>github</category>
    </item>
    <item>
      <title>A simple meme generator using ReactJS + FireStore</title>
      <dc:creator>Avinash</dc:creator>
      <pubDate>Sun, 22 May 2022 06:20:41 +0000</pubDate>
      <link>https://forem.com/avithe1/a-simple-meme-generator-using-reactjs-firestore-2f6p</link>
      <guid>https://forem.com/avithe1/a-simple-meme-generator-using-reactjs-firestore-2f6p</guid>
      <description>&lt;p&gt;This was my first ever ReactJS competition/hackathon, I did not win but I sincerely spent around 1 week coding for it and I was pretty happy with the outcome. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The challenge&lt;/strong&gt; : To create a ReactJS app that can generate a meme in the following way, a left panel with left heading and image and a right panel with the right heading and image. The heading can be on top of the image or the bottom.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Github repo&lt;/strong&gt; : &lt;a href="https://github.com/avithe1/memegenerator" rel="noopener noreferrer"&gt;https://github.com/avithe1/memegenerator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo&lt;/strong&gt; : &lt;a href="https://memegen-4c017.web.app/" rel="noopener noreferrer"&gt;https://memegen-4c017.web.app/&lt;/a&gt; (Read-only, create a firebase project to see 'Save Meme' functionality)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2s26465mv4uh4rgzguid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2s26465mv4uh4rgzguid.png" alt="memegenerator screenshot" width="386" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although memegenerator is a very small project, the following code could be useful for beginners:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use of TypeScript with ReactJS&lt;/li&gt;
&lt;li&gt;Use of ContextApi for data sharing among components&lt;/li&gt;
&lt;li&gt;Use of FireStore to store and retrieve meme data&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I also wanted to make the web app responsive but it's a long way to go. &lt;/p&gt;

&lt;p&gt;The website is hosted on Firebase hosting and now firebase also provides option for CI/CD github integration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Development&lt;/strong&gt;&lt;br&gt;
The code is bootstrapped using &lt;br&gt;
&lt;code&gt;npx create-react-app memegen --template typescript&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The application layout has two parts the header and the main section. The main section can toggle between CREATE and BROWSE.&lt;/p&gt;

&lt;p&gt;All components that require props follow the following TypeScript convention:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Props {
    appmode: MenuOptions,
    menuSelect: (option: MenuOptions) =&amp;gt; void
}

const Header: React.FC&amp;lt;Props&amp;gt; = ({ appmode, menuSelect }) =&amp;gt; {
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope the project helps someone trying to learn ReactJS and TypeScript.&lt;/p&gt;

&lt;p&gt;P.S. I am not a pro with TypeScript in fact this was my first attempt with TypeScript. Looking for some feedback. Thanks.&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
