ObjectThis configuration option only applies to server-side routing and can customize the access route of application entries.
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.
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>:
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
}
]
}Response headers can be set by configuring the resHeaders of the entry:
export default defineConfig({
server: {
routes: {
'page-a': {
route: ['/a', '/b'],
resHeaders: {
'x-modern-test': '1',
},
},
},
},
});
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.