logo
  • Guide
  • Config
  • Plugin
  • API
  • Examples
  • Community
  • Modern.js 2.x Docs
  • English
    • 简体中文
    • English
    • Configuration
      dev
      assetPrefix
      beforeStartUrl
      client
      hmr
      host
      https
      lazyCompilation
      liveReload
      port
      progressBar
      setupMiddlewares
      startUrl
      watchFiles
      writeToDisk
      bff
      prefix
      html
      appIcon
      crossorigin
      favicon
      inject
      meta
      mountId
      outputStructure
      scriptLoading
      tags
      templateParameters
      template
      title
      tools
      autoprefixer
      babel
      bundlerChain
      cssExtract
      cssLoader
      devServer
      htmlPlugin
      less
      lightningcssLoader
      minifyCss
      postcss
      rspack
      sass
      styleLoader
      swc
      tsChecker
      source
      aliasStrategy
      alias
      configDir
      decorators
      define
      disableDefaultEntries
      enableAsyncEntry
      entriesDir
      entries
      exclude
      globalVars
      include
      mainEntryName
      preEntry
      transformImport
      resolve
      aliasStrategy
      alias
      conditionNames
      dedupe
      extensions
      server
      baseUrl
      port
      publicRoutes
      routes
      ssrByEntries
      ssr
      output
      assetPrefix
      assetsRetry
      charset
      cleanDistPath
      convertToRem
      copy
      cssModules
      dataUriLimit
      disableCssModuleExtension
      disableInlineRuntimeChunk
      disableSvgr
      disableTsChecker
      distPath
      enableAssetManifest
      enableCssModuleTSDeclaration
      disableInlineRouteManifests
      externals
      filenameHash
      filename
      injectStyles
      inlineScripts
      inlineStyles
      legalComments
      minify
      overrideBrowserslist
      polyfill
      sourceMap
      splitRouteChunks
      ssg
      ssgByEntries
      svgDefaultExport
      tempDir
      plugins
      security
      checkSyntax
      nonce
      sri
      runtime
      Introduce
      plugins
      router
      performance
      buildCache
      bundleAnalyze
      chunkSplit
      dnsPrefetch
      preconnect
      prefetch
      preload
      printFileSize
      profile
      removeConsole
      removeMomentLocale
      experiments
      sourceBuild
      builderPlugins
      📝 Edit this page
      Previous pagepublicRoutesNext pagessrByEntries

      #server.routes

      • Type: Object
      • Default: Server-side routing rules generated based on file conventions, with one route rule generated for each entry, and the entry name is equal to the route path.

      This configuration option only applies to server-side routing and can customize the access route of application entries.

      #Custom access routes

      The key of the object is the name of the current application entry, and the value can be a string | Array<string>.

      When the value type is string, the current value represents the route path for accessing the entry.

      modern.config.ts
      export default defineConfig({
        server: {
          routes: {
            // Default route is /entryName1, customized to /p/test1
            entryName1: '/p/test1'
            // Supports dynamic server-side routing configuration
            entryName2: '/detail/:id'
          }
        }
      });

      Multiple access routes can also be set for the entry through Array<string>:

      modern.config.ts
      export default defineConfig({
        server: {
          routes: {
            'page-a': [`/a`, '/b'],
          },
        },
      });

      At this time, the page-a entry can be accessed through both the /a and /b routes.

      After executing the dev command, you can view two route records for the page-a entry in dist/route.json:

      {
        "routes": [
          {
            "urlPath": "/a",
            "entryName": "page-a",
            "entryPath": "html/page-a/index.html",
            "isSPA": true,
            "isSSR": false
          },
          {
            "urlPath": "/b",
            "entryName": "page-a",
            "entryPath": "html/page-a/index.html",
            "isSPA": true,
            "isSSR": false
          }
        ]
      }

      #Custom response headers

      Response headers can be set by configuring the resHeaders of the entry:

      modern.config.ts
      export default defineConfig({
        server: {
          routes: {
            'page-a': {
              route: ['/a', '/b'],
              resHeaders: {
                'x-modern-test': '1',
              },
            },
          },
        },
      });
      Note

      This configuration takes effect in both the production and development environments, and different response headers can be set according to the NODE_ENV to distinguish between environments. However, if you only need to set response headers in the development environment, it is recommended to use tools.devServer.headers.