{"id":10593,"date":"2024-01-15T21:39:54","date_gmt":"2024-01-15T21:39:54","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=10593"},"modified":"2024-01-15T21:50:24","modified_gmt":"2024-01-15T21:50:24","slug":"multi-spa-using-next-js","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/multi-spa-using-next-js\/","title":{"rendered":"Multi-SPA using Next.js"},"content":{"rendered":"<p>With the next.config.js we can do some neat things, such as multi-SPA routing.<\/p>\n<p>If you create yourself two Next.js apps, the &#8220;main&#8221; one is named <em>home<\/em> in my example and the second is a <em>catalog<\/em> and we will be able to navigate to. <\/p>\n<p>Go to the next.config.js of the <em>home<\/em> app. and add the <em>catalog<\/em> changes listed below<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nconst nextConfig = {\r\n    reactStrictMode: true,\r\n    async rewrites() {\r\n        return &#x5B;\r\n            {\r\n                source: '\/:path*',\r\n                destination: '\/:path*'\r\n            },\r\n            {\r\n                source: '\/catalog',\r\n                destination: 'http:\/\/localhost:3001\/catalog'\r\n            },\r\n            {\r\n                source: '\/catalog\/:path*',\r\n                destination: 'http:\/\/localhost:3001\/catalog\/:path*'\r\n            },\r\n        ]\r\n    }\r\n}\r\n<\/pre>\n<p>in the <em>catalog<\/em> app go to it&#8217;s next.config.js and have it look like this<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nconst nextConfig = {\r\n    basePath:'\/catalog'\r\n}\r\n<\/pre>\n<p>then when you click a hyperlink to your second app it will actually appear as if it&#8217;s simply a page on the first app, with the same port.<\/p>\n<p>Code is available on github as <a href=\"https:\/\/github.com\/putridparrot\/blog-projects\/tree\/master\/multiSpa\" rel=\"noopener\" target=\"_blank\">multiSpa<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the next.config.js we can do some neat things, such as multi-SPA routing. If you create yourself two Next.js apps, the &#8220;main&#8221; one is named home in my example and the second is a catalog and we will be able to navigate to. Go to the next.config.js of the home app. and add the catalog [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[715],"tags":[],"class_list":["post-10593","post","type-post","status-publish","format-standard","hentry","category-next-js"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=10593"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10593\/revisions"}],"predecessor-version":[{"id":10598,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10593\/revisions\/10598"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=10593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=10593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=10593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}