So far, I made the following setup:
- Created project in Ruby on Rails 7
- Created Vue project as a directory inside the
appdirectory of rails - The Vue project is based on: Vue3, Vue-router and Vuex
- I configured the Vue project on build to output in Rails
pubic/spadirectory, i.e. serve the SPA app in the static files - So far so good, when I run Rails and build the Vue project, everything is working as expected
- When I click on a link on the Vue page, I'm expectedly going to the desired page
- However, if I refresh on a routed page (e.g.
spa/about) Rails throws Routing Error - In addition, if I try typing the route manually, I get the Routing Error again.
I'm figuring that I need a way to tell Rails to always redirect to the SPA app every time the route prefix is spa
Is there a way to config rails to do that?
something like this (in route.rb)
# every URL prefix is with spa, redirect to static file `spa/index.html`
get "spa#*" => "spa#*"
# or maybe like this?
prefix :spa # there's no `prefix` method option obviously