{"id":107,"date":"2021-12-29T14:58:54","date_gmt":"2021-12-29T14:58:54","guid":{"rendered":"http:\/\/frontendguruji.com\/?p=107"},"modified":"2021-12-30T11:07:48","modified_gmt":"2021-12-30T11:07:48","slug":"warn-export-switch-imported-as-switch-was-not-found-in-react-router-dom","status":"publish","type":"post","link":"https:\/\/frontendguruji.com\/blog\/warn-export-switch-imported-as-switch-was-not-found-in-react-router-dom\/","title":{"rendered":"WARN export &#8216;Switch&#8217; (imported as &#8216;Switch&#8217;) was not found in &#8216;react-router-dom&#8217;"},"content":{"rendered":"\n<p>Hello Friends &#x1f64f;, today I was <a rel=\"noreferrer noopener\" href=\"http:\/\/frontendguruji.com\/how-to-setup-a-react-js-project-from-scratch-without-create-react-app\/\" target=\"_blank\">setting up a new React project from scratch without using create-react-app<\/a> and after doing all the required steps when I compiled the React App, I got below warning&#x1f62e;:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img width=\"685\" height=\"183\" src=\"http:\/\/frontendguruji.com\/wp-content\/uploads\/2021\/12\/image-7.png\" alt=\"\" class=\"wp-image-108\" srcset=\"https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-7.png 685w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-7-300x80.png 300w\" sizes=\"(max-width: 685px) 100vw, 685px\" \/><figcaption><span style=\"color:#cccccc\" class=\"has-inline-color\">export &#8216;Switch&#8217; (imported as &#8216;Switch&#8217;) was not found in &#8216;react-router-dom&#8217; <\/span><\/figcaption><\/figure>\n\n\n\n<p>So basically it is complaining for the <strong>Switch<\/strong> here, below is the code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img width=\"673\" height=\"351\" src=\"http:\/\/frontendguruji.com\/wp-content\/uploads\/2021\/12\/image-8.png\" alt=\"\" class=\"wp-image-109\" srcset=\"https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-8.png 673w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-8-300x156.png 300w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><\/figure>\n\n\n\n<p>Then I did a search on this error and found that in it is due to changes in the v6 of <strong>react-router<\/strong>. Then I went to their <a rel=\"noreferrer noopener\" href=\"https:\/\/reactrouter.com\/docs\/en\/v6\/upgrading\/v5#upgrade-all-switch-elements-to-routes\" target=\"_blank\">documentation <\/a>and found out that now Switch is replaced by <em>Routers<\/em>.  And there are many different changes, you can go through the documentation once if you are using v6 of the react-router.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img width=\"1024\" height=\"323\" src=\"http:\/\/frontendguruji.com\/wp-content\/uploads\/2021\/12\/image-9-1024x323.png\" alt=\"\" class=\"wp-image-110\" srcset=\"https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-9-1024x323.png 1024w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-9-300x95.png 300w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-9-768x242.png 768w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-9.png 1060w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>So I made the change and App started compiling without any warning &#x1f973;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img width=\"657\" height=\"358\" src=\"http:\/\/frontendguruji.com\/wp-content\/uploads\/2021\/12\/image-11.png\" alt=\"\" class=\"wp-image-112\" srcset=\"https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-11.png 657w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-11-300x163.png 300w\" sizes=\"(max-width: 657px) 100vw, 657px\" \/><\/figure>\n\n\n\n<p>But now when I went to the browser, I got surprised to see that nothing is rendering &#x1f62e;.<\/p>\n\n\n\n<p>Then again I went to the documentation and found out that way of writing Route is also changed in v6 &#x1f625;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img width=\"1024\" height=\"265\" src=\"http:\/\/frontendguruji.com\/wp-content\/uploads\/2021\/12\/image-12-1024x265.png\" alt=\"\" class=\"wp-image-115\" srcset=\"https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-12-1024x265.png 1024w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-12-300x78.png 300w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-12-768x199.png 768w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-12.png 1044w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Again did the changes and now all is working fine &#x1f605;&#x1f973;&#x1f973;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img width=\"564\" height=\"322\" src=\"http:\/\/frontendguruji.com\/wp-content\/uploads\/2021\/12\/image-13.png\" alt=\"\" class=\"wp-image-116\" srcset=\"https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-13.png 564w, https:\/\/frontendguruji.com\/blog\/wp-content\/uploads\/2021\/12\/image-13-300x171.png 300w\" sizes=\"(max-width: 564px) 100vw, 564px\" \/><\/figure>\n\n\n\n<p>Thanks &#x1f64f;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Friends &#x1f64f;, today I was setting up a new React project from scratch without using create-react-app and after doing all the required steps when I compiled the React App, I got below warning&#x1f62e;: So basically it is complaining for the Switch here, below is the code: Then I did a search on this error &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/frontendguruji.com\/blog\/warn-export-switch-imported-as-switch-was-not-found-in-react-router-dom\/\"> <span class=\"screen-reader-text\">WARN export &#8216;Switch&#8217; (imported as &#8216;Switch&#8217;) was not found in &#8216;react-router-dom&#8217;<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[30],"tags":[12,31,13,34,32],"_links":{"self":[{"href":"https:\/\/frontendguruji.com\/blog\/wp-json\/wp\/v2\/posts\/107"}],"collection":[{"href":"https:\/\/frontendguruji.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendguruji.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendguruji.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendguruji.com\/blog\/wp-json\/wp\/v2\/comments?post=107"}],"version-history":[{"count":0,"href":"https:\/\/frontendguruji.com\/blog\/wp-json\/wp\/v2\/posts\/107\/revisions"}],"wp:attachment":[{"href":"https:\/\/frontendguruji.com\/blog\/wp-json\/wp\/v2\/media?parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendguruji.com\/blog\/wp-json\/wp\/v2\/categories?post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendguruji.com\/blog\/wp-json\/wp\/v2\/tags?post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}