0

I have Multi Zone setup between two applications:

  • Home App
  • Blog App

When I am on a page within the Blog app and try to link back to the Home app, either using Link or router.push("/"), it takes me to the base path of the Blog app.

Inside the next.config.js, I've set it up as following:

/** @type {import('next').NextConfig} */

const withTM = require('next-transpile-modules')(['@workflow/shared-core']);

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  experimental: {
    externalDir: true
  },
  basePath: '/blog',
  rewrites: async () => {
    return [
      {
        source: "/",
        destination: "http://localhost:5001",
        basePath: false
      }
    ]
  }
}

module.exports = withTM(nextConfig)

My understanding was that when a rewrite is setup with the basePath set to false, it would fallback completely the URL in the destination property.

Any ideas?

2 Answers2

1

Unfortunately you can't use next router to jump between multi zones. Each new multi zone is basically a new next app with its own instance of router, so for your blog app the base route would be /blog/. To jump to the other app you will have to use either an <a href="#"> tag with href attribute or manually change the window.location.href = .... pointing to the route you want. For example if base path is '/account' and you want to navigate to that from '/blog', you will have to do window.location.href = '/account'.

0

I found a solution in an answer on another thread 73665831)

in /blog next.config.js

Please be aware that Next.js warns: " warning - You have enabled an experimental feature (manualClientBasePath) in next.config.js. warning - Experimental features are not covered by semver, and they may cause unexpected or broken application behavior. Use them at your own risk."

I'm not sure if there's a better solution available at this point, but this one works for me.

  • HI Welcome to Stack Overflow. While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Alpha Sep 01 '23 at 05:16