<?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>DEV Community: Will Feldman</title>
    <description>The latest articles on DEV Community by Will Feldman (@willfeldman).</description>
    <link>https://dev.to/willfeldman</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%2F891088%2Fb0676c84-d1d0-4807-aeae-b396f65a40c5.jpeg</url>
      <title>DEV Community: Will Feldman</title>
      <link>https://dev.to/willfeldman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/willfeldman"/>
    <language>en</language>
    <item>
      <title>React router having an issue with correctly routing to component</title>
      <dc:creator>Will Feldman</dc:creator>
      <pubDate>Wed, 13 Jul 2022 00:29:29 +0000</pubDate>
      <link>https://dev.to/willfeldman/react-router-having-an-issue-with-correctly-routing-to-component-fm1</link>
      <guid>https://dev.to/willfeldman/react-router-having-an-issue-with-correctly-routing-to-component-fm1</guid>
      <description>&lt;p&gt;My program is supposed to route to a component when going to the local path &lt;code&gt;/experience/:id&lt;/code&gt; but it is only working on &lt;code&gt;localhost&lt;/code&gt; when ran with &lt;code&gt;npm start&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;I currently have my site uploaded to &lt;code&gt;/test&lt;/code&gt; subdirectory (&lt;a href="https://willfeldman.com/test"&gt;willfeldman.com/test&lt;/a&gt;). I set &lt;code&gt;basename="test"&lt;/code&gt; on the Router. When I go to the route &lt;code&gt;/test/experience/1&lt;/code&gt; after uploading the code to my site, I see a blank page and there is a console error saying &lt;code&gt;Uncaught SyntaxError: Unexpected token '&amp;lt;' (at main.694b5be9.js:1:1)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q3vsTbxb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gcmrk6fx234ur6gm3uc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q3vsTbxb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gcmrk6fx234ur6gm3uc.png" alt="How it looks on localhost" width="880" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0BJ6jn5G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eq3fxr1b4hot8l0ah4pv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0BJ6jn5G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eq3fxr1b4hot8l0ah4pv.png" alt="How it looks on site" width="880" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A couple of things (not sure what will be relevant to fixing the blank page ): &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I converted my &lt;code&gt;App.jsx&lt;/code&gt; file to a Typescript file named &lt;code&gt;App.tsx&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I’m using Hostgator to host my site&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I am using &lt;code&gt;useParams&lt;/code&gt; from react router in my &lt;code&gt;&amp;lt;ExperienceView /&amp;gt;&lt;/code&gt; component that I route to from &lt;code&gt;/test/experience/1&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I have an .htaccess in the &lt;code&gt;public&lt;/code&gt; folder that contains the following code as suggested on the &lt;a href="https://create-react-app.dev/docs/deployment/#serving-apps-with-client-side-routing"&gt;Create React App documentation&lt;/a&gt;. It works for rerouting invalid URLs to my React error component &lt;code&gt;&amp;lt;Error /&amp;gt;&lt;/code&gt; as specified in my Router, but it does not work for the route &lt;code&gt;/test/experience/1&lt;/code&gt;&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;Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I had the same issue when running the static files from &lt;code&gt;build&lt;/code&gt; with &lt;code&gt;npx lite-server&lt;/code&gt; and the way I fixed it was by uploading a folder called &lt;code&gt;build/test/experience&lt;/code&gt; that contained &lt;code&gt;index.html&lt;/code&gt;, &lt;code&gt;manifest.json&lt;/code&gt;, and the &lt;code&gt;static&lt;/code&gt; folder. This makes me think it may be something with a setting on the router that needs to be configured, but I am not sure. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Source code: &lt;a href="https://github.com/willfeldman/Portfolio"&gt;https://github.com/willfeldman/Portfolio&lt;/a&gt; -&amp;gt; uploaded to &lt;a href="https://willfeldman.com/test"&gt;https://willfeldman.com/test&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
