本地开发中配置了接口了接口代理
nitro: {
devProxy: {
"/api": {
target: 'http://127.0.0.1:5000',
changeOrigin: true,
},
},
},
但是在服务端渲染的过程中会报错
[Vue Router warn]: No match found for location with path "/api/article/page"
???
之前使用nuxt2没有遇到过这种问题,代理请求怎么跑到匹配路由上了,很懵逼
请求中设置ssr:false,接口只在客户端渲染没问题,但是我的页面需要再服务端渲染
赶紧翻文档瞅瞅
找到了这个配置:
routeRules: {
'/blog/**': { swr: true },
'/blog/**': { swr: 600 },
'/blog/**': { static: true },
'/blog/**': { cache: { /* cache options*/ } },
'/assets/**': { headers: { 'cache-control': 's-maxage=0' } },
'/api/v1/**': { cors: true, headers: { 'access-control-allow-methods': 'GET' } },
'/old-page': { redirect: '/new-page' }, // uses status code 307 (Temporary Redirect)
'/old-page2': { redirect: { to:'/new-page2', statusCode: 301 } },
'/old-page/**': { redirect: '/new-page/**' },
'/proxy/example': { proxy: 'https://example.com' },
'/proxy/**': { proxy: '/api/**' },
}
配置一下toureRules的代理就可以了
routeRules:{
'/api/**':{
proxy:'http://127.0.0.1:5000/api/**'
}
},