From fe41d4b75b43a5a4255d9656384d485c45cf2cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 20 Aug 2018 14:59:08 +0200 Subject: [PATCH] example: Add routes-meta example --- examples/routes-meta/layouts/default.vue | 67 ++++++++++++++++++++++ examples/routes-meta/middleware/theme.js | 5 ++ examples/routes-meta/nuxt.config.js | 6 ++ examples/routes-meta/package.json | 12 ++++ examples/routes-meta/pages/about.vue | 32 +++++++++++ examples/routes-meta/pages/index.vue | 19 ++++++ examples/routes-meta/pages/parent.vue | 16 ++++++ examples/routes-meta/pages/parent/blue.vue | 17 ++++++ examples/routes-meta/store/index.js | 9 +++ 9 files changed, 183 insertions(+) create mode 100644 examples/routes-meta/layouts/default.vue create mode 100644 examples/routes-meta/middleware/theme.js create mode 100644 examples/routes-meta/nuxt.config.js create mode 100644 examples/routes-meta/package.json create mode 100644 examples/routes-meta/pages/about.vue create mode 100644 examples/routes-meta/pages/index.vue create mode 100644 examples/routes-meta/pages/parent.vue create mode 100644 examples/routes-meta/pages/parent/blue.vue create mode 100644 examples/routes-meta/store/index.js diff --git a/examples/routes-meta/layouts/default.vue b/examples/routes-meta/layouts/default.vue new file mode 100644 index 0000000000..5012714058 --- /dev/null +++ b/examples/routes-meta/layouts/default.vue @@ -0,0 +1,67 @@ + + + diff --git a/examples/routes-meta/middleware/theme.js b/examples/routes-meta/middleware/theme.js new file mode 100644 index 0000000000..b2cd3f1759 --- /dev/null +++ b/examples/routes-meta/middleware/theme.js @@ -0,0 +1,5 @@ +export default ({ route, app }) => { + // Take the last value (latest route child) + const theme = route.meta.reduce((theme, meta) => meta.theme || theme, 'light') + app.store.commit('SET_THEME', theme) +} diff --git a/examples/routes-meta/nuxt.config.js b/examples/routes-meta/nuxt.config.js new file mode 100644 index 0000000000..e97a8c3a3b --- /dev/null +++ b/examples/routes-meta/nuxt.config.js @@ -0,0 +1,6 @@ +export default { + router: { + middleware: ['theme'] + }, + css: ['wingcss'] +} diff --git a/examples/routes-meta/package.json b/examples/routes-meta/package.json new file mode 100644 index 0000000000..f3abf22fa9 --- /dev/null +++ b/examples/routes-meta/package.json @@ -0,0 +1,12 @@ +{ + "name": "example-hello-world", + "dependencies": { + "nuxt-edge": "latest", + "wingcss": "^1.0.0-beta" + }, + "scripts": { + "dev": "nuxt", + "build": "nuxt build", + "start": "nuxt start" + } +} diff --git a/examples/routes-meta/pages/about.vue b/examples/routes-meta/pages/about.vue new file mode 100644 index 0000000000..89b92384f8 --- /dev/null +++ b/examples/routes-meta/pages/about.vue @@ -0,0 +1,32 @@ + + + + + diff --git a/examples/routes-meta/pages/index.vue b/examples/routes-meta/pages/index.vue new file mode 100644 index 0000000000..2e31ae4815 --- /dev/null +++ b/examples/routes-meta/pages/index.vue @@ -0,0 +1,19 @@ + + + diff --git a/examples/routes-meta/pages/parent.vue b/examples/routes-meta/pages/parent.vue new file mode 100644 index 0000000000..6258e78f51 --- /dev/null +++ b/examples/routes-meta/pages/parent.vue @@ -0,0 +1,16 @@ + + + diff --git a/examples/routes-meta/pages/parent/blue.vue b/examples/routes-meta/pages/parent/blue.vue new file mode 100644 index 0000000000..07ea5f6401 --- /dev/null +++ b/examples/routes-meta/pages/parent/blue.vue @@ -0,0 +1,17 @@ + + + diff --git a/examples/routes-meta/store/index.js b/examples/routes-meta/store/index.js new file mode 100644 index 0000000000..651d618645 --- /dev/null +++ b/examples/routes-meta/store/index.js @@ -0,0 +1,9 @@ +export const state = () => ({ + theme: 'light' +}) + +export const mutations = { + SET_THEME(state, theme) { + state.theme = theme + } +}