npx create-razzle-app --example with-vue-router with-vue-router
cd with-vue-router
yarn start
This shows how to setup Vue Router with Vue and Razzle.
Here is a list of changes from Razzle's base template:
- Install
connect-history-api-fallback
,eslint-plugin-vue
,razzle-plugin-vue
,vue-template-compiler
as devDependenciesconnect-history-api-fallback
is required forvue-router
's history mode.vue-template-compiler
is required byvue-router
- Add
vue
to the razzle plugins config - Add custom
.eslintrc
to followvue
recommended, andbabel-eslint
- Install
vue
,vue-router
,vue-server-renderer
as dependencies - Remove
react
,react-dom
,react-router-dom
entirely - Update
server/server.js
to usevue-server-renderer
'srenderToString
function, enable history mode, add server-side routing - Update
client.js
to wait tillvue-router
is ready, mount Vue to#app
and start HMR App.vue
contains only a<router-view>
component, which then renders every other page inside itHome.vue
,About.vue
andPageNotFound.vue
are addedrouter.js
exports aVueRouter
as well as setting up the page routes