I wanted to do hosting Nuxt.js application under test directory (like https://dev.example.amplify.com/test) with AWS Amplify Console. But, I couldn’t find an article how to do it and I tried with some ways.
Finally I found that Amplify Console redirect function and Nuxt.js generate.dir property can be a solution. I think they are basic one but I was not familiar with them.
I referred to the following web site for setting up environment and hosting Nuxt.js app on Amplify Console. (npm install 、amplify configure 、npx create-nuxt-app 、npm run dev 、 npm run generate 、amplify init 、amplify add hosting 、amplify publish command parts. Sorry the web site is Japanese.)
To build and deploy, please run “npm run generate” and “amplify publish” commands.
After deploy, you cannot see the page correctly with “https://dev.<APP ID>.amplifyapp.com/” and “https://dev.<APP ID>.amplifyapp.com/test/”.
Then, after adding a rule with the following setting, you can see the page correctly.
Source address : /test/<*>
Target address : /<*>
Type : 200 (Rewrite)
Please access to “https://dev.<APP ID>.amplifyapp.com/test/” (please clear browser cache).
Changing generate.dir property in nuxt.config.js like the following allows us to deploy files under “/test/”.
Please change img tag src URL to “/test/vuetify-logo.svg” in components/VuetifyLogo.vue to correct Vuetify logo path.
Please build with clearning dist directory like following (please remove redirect rule if amplify console has /test/<*> rule). After that, you can see the page correctly.