Skip to content

armgit / dashy

Public Imported from GitHub
0

🚀 A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

✨ All multi view, config, section paths working

Alicia Sykes382f37abce0d
diff --git a/docs/management.md b/docs/management.md
index e2ab9bd0..b63f9b13 100644
--- a/docs/management.md
+++ b/docs/management.md
@@ -806,7 +806,7 @@ server {
}
```
-To use HTML5 history mode (the default - controlled via the `VUE_APP_ROUTING_MODE` build-time env var), replace the inside of the location block with: `try_files $uri $uri/ /index.html;`.
+To use HTML5 history mode (the default - controlled via the `VITE_APP_ROUTING_MODE` build-time env var), replace the inside of the location block with: `try_files $uri $uri/ /index.html;`.
Then upload the build contents of Dashy's dist directory to that location.
For example: `scp -r ./dist/* [username]@[server_ip]:/var/www/dashy/html`
diff --git a/docs/pages-and-sections.md b/docs/pages-and-sections.md
index 38f4b2e2..6de0bf59 100644
--- a/docs/pages-and-sections.md
+++ b/docs/pages-and-sections.md
@@ -67,6 +67,34 @@ Only top-level fields supported by sub-pages are `pageInfo` and `sections`. The
Note that since page paths are required by the router, they are set at build-time, not run-time, and so a rebuild (happens automatically) is required for changes to page paths to take effect (this only applies to changes to the `pages` array, rebuild isn't required for editing page content).
+### URL Structure
+
+Every view in Dashy shares the same URL shape, so any config can be reached from any view:
+
+```
+/ Landing — whichever view you set as the default
+/<view> Root config in <view>
+/<view>/<page> Sub-config <page> in <view>
+/<view>/<page>/<section> Single section of <page> in <view>
+/<view>/main/<section> Single section of the root config (main is a reserved page id)
+```
+
+`<view>` is one of `home`, `minimal`, or `workspace`. `<page>` is the sub-config id — the sub-page's `name` (from the `pages` array) converted to lowercase-and-dashes (emoji and other non-word characters stripped). `<section>` follows the same slugging rules. Workspace has no single-section URL; it uses its sidebar instead.
+
+Examples:
+
+```
+/home Home view, main config
+/home/homelab Home view, "Homelab" sub-config
+/home/homelab/media Home view, "Homelab" sub-config, "Media" section only
+/home/main/getting-started Home view, main config, "Getting Started" section only
+/minimal/homelab Minimal view, "Homelab" sub-config
+/minimal/homelab/media Minimal view, "Homelab" sub-config, "Media" section pre-selected
+/workspace/homelab Workspace view, "Homelab" sub-config
+```
+
+The view switcher, sub-page nav links, and section deep-links all preserve your current view and sub-page — so clicking through a single-section view and then hitting "back to all" returns you to the same sub-page you came from.
+
## Sub-Items
A normal section will contain zero or more items, for example:
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index ebc07ba4..4e58733e 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -13,6 +13,10 @@
- [404 On Static Hosting](#404-on-static-hosting)
- [404 from Mobile Home Screen](#404-after-launch-from-mobile-home-screen)
- [404 On Multi-Page Apps](#404-on-multi-page-apps)
+- [Dashy hosted at a sub-path](#dashy-hosted-at-a-sub-path-eg-examplecomdashy)
+- [Sub-page shows "Unable to find config for ..."](#sub-page-shows-unable-to-find-config-for-)
+- [Sub-page missing from nav, or won't open when clicked](#sub-page-missing-from-nav-or-wont-open-when-clicked)
+- [Sub-page ignores its theme, layout or appConfig](#sub-page-ignores-its-theme-layout-or-appconfig)
- [Yarn Build or Run Error](#yarn-error)
- [Remote Config Not Loading](#remote-config-not-loading)
- [High CPU or RAM Usage on Startup](#high-cpu-or-ram-usage-on-startup)
@@ -149,16 +153,16 @@ Content-Security-Policy: frame-ancestors 'self' https://[dashy-location]/
If you're seeing Dashy's 404 page on initial load/ refresh, and then the main app when you go back to Home, then this is likely caused by the Vue router, and if so can be fixed in one of two ways.
-The first solution is to switch the routing mode, from HTML5 `history` mode to `hash` mode, by rebuilding Dashy with the `VUE_APP_ROUTING_MODE=hash` build-time environment variable set.
+The first solution is to switch the routing mode, from HTML5 `history` mode to `hash` mode, by rebuilding Dashy with the `VITE_APP_ROUTING_MODE=hash` build-time environment variable set.
-If this works, but you wish to continue using HTML5 history mode, then a bit of extra [server configuration](/docs/management.md#web-server-configuration) is required. This is explained in more detaail in the [Vue Docs](https://router.vuejs.org/guide/essentials/history-mode.html). Once completed, you can then use `VUE_APP_ROUTING_MODE=history` (the default) again, for neater URLs.
+If this works, but you wish to continue using HTML5 history mode, then a bit of extra [server configuration](/docs/management.md#web-server-configuration) is required. This is explained in more detaail in the [Vue Docs](https://router.vuejs.org/guide/essentials/history-mode.html). Once completed, you can then use `VITE_APP_ROUTING_MODE=history` (the default) again, for neater URLs.
---
## 404 after Launch from Mobile Home Screen
Similar to the above issue, if you get a 404 after using iOS and Android's "Add to Home Screen" feature, then this is caused by Vue router.
-It can be fixed by rebuilding Dashy with the `VUE_APP_ROUTING_MODE=hash` build-time environment variable set.
+It can be fixed by rebuilding Dashy with the `VITE_APP_ROUTING_MODE=hash` build-time environment variable set.
See also: [#628](https://github.com/Lissy93/dashy/issues/628), [#762](https://github.com/Lissy93/dashy/issues/762)
@@ -166,12 +170,60 @@ See also: [#628](https://github.com/Lissy93/dashy/issues/628), [#762](https://gi
## 404 On Multi-Page Apps
-Similar to above, if you get a 404 error when visiting a page directly on multi-page apps, then this can be fixed by rebuilding Dashy with the `VUE_APP_ROUTING_MODE=hash` build-time environment variable set, then refreshing the page.
+Similar to above, if you get a 404 error when visiting a page directly on multi-page apps, then this can be fixed by rebuilding Dashy with the `VITE_APP_ROUTING_MODE=hash` build-time environment variable set, then refreshing the page.
See also: [#670](https://github.com/Lissy93/dashy/issues/670), [#763](https://github.com/Lissy93/dashy/issues/763)
---
+## Dashy hosted at a sub-path (e.g. `example.com/dashy`)
+
+If the homepage works but sub-page links 404, or assets fail to load, it's almost always the base path.
+Rebuild with `BASE_URL` set to the sub-path - leading slash, no trailing slash:
+
+Vue Router uses this to prefix every route. Without it, links resolve to `/home/...` instead of `/dashy/home/...` and skip your reverse proxy altogether. More detail in [web-server configuration](/docs/management.md#web-server-configuration).
+
+---
+
+## Sub-page shows "Unable to find config for ..."
+
+This means Dashy couldn't match the URL segment to any entry in your `pages:` list. A few causes:
+
+### Old bookmark from before an upgrade
+Slugs are now trimmed more aggressively (e.g. `🌐 Command Center` used to give `-command-center`, now gives `command-center`). Re-bookmark from the nav, or update the URL by hand.
+
+### The page was renamed or removed
+The URL no longer resolves to anything. Check the `pages:` array in `conf.yml` and confirm the sub-page still exists.
+
+### The path points at an unreachable file
+If the sub-config YAML can't be fetched (404, CORS, auth), you'll see "Unable to load config from ..." instead. Verify the `path:` is correct, reachable from the browser, and CORS-open if remote.
+
+### Page name literally "Main"
+`main` is reserved in the URL scheme to mean "the root config". A page named "Main" becomes reachable at `/home/main-page` (not `/home/main`). Rename the page if that's confusing.
+
+### Service worker is serving a stale app
+Hard-refresh (<kbd>Ctrl</kbd> + <kbd>F5</kbd>) after a major upgrade. The PWA cache may still be pointing at old routes. Also see [Styles and Assets not Updating](#styles-and-assets-not-updating).
+
+---
+
+## Sub-page missing from nav, or won't open when clicked
+
+If page defined in `pages:` is nowhere in the nav bar, or its link goes to a different page, then there's probably something wrong with the name you chose. Note that Dashy strips out any non-alphanumeric characters.
+- Ensure each page does have a valid `name` and `path` field
+- Check two pages don't have the same/similar name
+- Check each page has a name which has at least some alpha-numeric characters
+- Very long names could be being stripped/truncated
+
+---
+
+## Sub-page ignores its theme, layout or appConfig
+
+This is by design. Only the `appConfig` from your root `conf.yml` is used - theme, layout, iconSize, statusCheck, etc. are inherited globally so behaviour stays consistent across pages.
+
+If you put `appConfig` inside a sub-page YAML, it's silently dropped on load. Move the values to the root config. See [Restrictions](/docs/pages-and-sections.md#restrictions).
+
+---
+
## Yarn Error
For more info, see [Issue #1](https://github.com/Lissy93/dashy/issues/1)
@@ -213,7 +265,7 @@ When the Dashy container first starts, it runs a Vue production build in paralle
**To work around it:**
-1. **Allocate at least 1 GB of RAM to the container** — 2 GB is recommended on Raspberry Pi or low-powered VMs. Anything below 512 MB is unlikely to complete the first build.
+1. **Allocate at least 1 GB of RAM to the container** - 2 GB is recommended on Raspberry Pi or low-powered VMs. Anything below 512 MB is unlikely to complete the first build.
2. **Set explicit Docker resource limits** so the build can't starve other services on the same host:
```yaml
services:
@@ -225,8 +277,8 @@ When the Dashy container first starts, it runs a Vue production build in paralle
memory: 2g
cpus: '1.5'
```
-3. **Wait it out** — once the build completes, idle CPU drops to near zero and idle RAM is typically under 100 MB. If you watch `docker stats`, you'll see the spike taper off.
-4. If the spike never tapers (i.e., Dashy stays at 100% CPU forever and never serves the page), see [Heap limit Allocation failed](#ineffective-mark-compacts-near-heap-limit-allocation-failed) below — that usually means the build was killed mid-way and is being retried.
+3. **Wait it out** - once the build completes, idle CPU drops to near zero and idle RAM is typically under 100 MB. If you watch `docker stats`, you'll see the spike taper off.
+4. If the spike never tapers (i.e., Dashy stays at 100% CPU forever and never serves the page), see [Heap limit Allocation failed](#ineffective-mark-compacts-near-heap-limit-allocation-failed) below - that usually means the build was killed mid-way and is being retried.
See also: [#1585](https://github.com/Lissy93/dashy/issues/1585), [#969](https://github.com/Lissy93/dashy/issues/969), [#1500](https://github.com/Lissy93/dashy/issues/1500), [#877](https://github.com/Lissy93/dashy/issues/877)
@@ -262,7 +314,7 @@ See also [#624](https://github.com/Lissy93/dashy/issues/624)
## Container Crashes or Restart Loop After Saving Config
-If your Dashy container crashes or enters a restart loop the moment you click **Save to Disk** in the editor — particularly with logs that include something like:
+If your Dashy container crashes or enters a restart loop the moment you click **Save to Disk** in the editor - particularly with logs that include something like:
```text
node:_http_outgoing:652
@@ -358,7 +410,7 @@ See also: #479, #409, #507, #491, #341, #520
If your IdP rejects the login with an *"invalid client"* / *"client not found"* error, and your `clientId` is a long numeric value, the cause is almost certainly YAML number parsing.
-YAML parses unquoted numeric tokens as Numbers, and JavaScript can't represent integers larger than 2^53 (~16 digits) without losing precision. So an unquoted numeric `clientId` will be silently truncated (e.g. `918756876419824312` → `918756876419824300`), or — for very large values — converted to scientific notation (e.g. `9.187568764198242e+37`), and the IdP will reject it.
+YAML parses unquoted numeric tokens as Numbers, and JavaScript can't represent integers larger than 2^53 (~16 digits) without losing precision. So an unquoted numeric `clientId` will be silently truncated (e.g. `918756876419824312` → `918756876419824300`), or - for very large values - converted to scientific notation (e.g. `9.187568764198242e+37`), and the IdP will reject it.
The fix is to wrap the `clientId` in quotes in your `conf.yml` so it gets parsed as a string:
@@ -551,7 +603,7 @@ If you've set `PORT` to override the default 8080, the healthcheck honors the sa
### Slow startup on weak hardware
-The healthcheck has a `--start-period=30s` grace period before failures count against the container. If your host takes longer than 30 seconds for the initial Vue build to complete (common on Pi 3 or similar), the first few healthchecks will fail and you may briefly see `unhealthy`. After the build finishes, subsequent checks should pass — see [High CPU or RAM Usage on Startup](#high-cpu-or-ram-usage-on-startup) below.
+The healthcheck has a `--start-period=30s` grace period before failures count against the container. If your host takes longer than 30 seconds for the initial Vue build to complete (common on Pi 3 or similar), the first few healthchecks will fail and you may briefly see `unhealthy`. After the build finishes, subsequent checks should pass - see [High CPU or RAM Usage on Startup](#high-cpu-or-ram-usage-on-startup) below.
See also: [#1410](https://github.com/Lissy93/dashy/issues/1410)
@@ -622,7 +674,7 @@ For testing purposes, you can use an addon, which will disable the CORS checks.
## CORS Proxy `connect ECONNREFUSED ...` or `getaddrinfo ENOTFOUND ...`
-The target host is unreachable from the Dashy container. If the target is on the same host as Dashy, **don't use `localhost`** — inside a Docker container that resolves to the container itself, not the host. Use the host's LAN IP, the Docker bridge gateway, or `host.docker.internal` (on Docker Desktop). If the target is on a different Docker network, attach Dashy to that network too.
+The target host is unreachable from the Dashy container. If the target is on the same host as Dashy, **don't use `localhost`** - inside a Docker container that resolves to the container itself, not the host. Use the host's LAN IP, the Docker bridge gateway, or `host.docker.internal` (on Docker Desktop). If the target is on a different Docker network, attach Dashy to that network too.
---
@@ -630,8 +682,8 @@ The target host is unreachable from the Dashy container. If the target is on the
To prevent the CORS proxy from being abused as a Server-Side Request Forgery vector, Dashy refuses to proxy a small number of host/scheme combinations by default:
-- **Cloud instance metadata services** — `169.254.169.254`, `metadata.google.internal`, and the matching IPv6 forms. These are reserved magic addresses on AWS, Azure, GCP, DigitalOcean, Hetzner, Oracle Cloud and most other providers. A widget that successfully fetches them on a cloud-hosted Dashy can leak the host's IAM credentials, so they're blocked unconditionally.
-- **Non-HTTP(S) schemes** — `file://`, `ftp://`, `gopher://`, `javascript:`, `data:`, and similar. The proxy is meant for HTTP APIs only.
+- **Cloud instance metadata services** - `169.254.169.254`, `metadata.google.internal`, and the matching IPv6 forms. These are reserved magic addresses on AWS, Azure, GCP, DigitalOcean, Hetzner, Oracle Cloud and most other providers. A widget that successfully fetches them on a cloud-hosted Dashy can leak the host's IAM credentials, so they're blocked unconditionally.
+- **Non-HTTP(S) schemes** - `file://`, `ftp://`, `gopher://`, `javascript:`, `data:`, and similar. The proxy is meant for HTTP APIs only.
If you're running Dashy in a fully isolated/private environment and you've deliberately decided you want to allow these (for example, you genuinely need to query your cloud provider's metadata API from a widget), you can opt out of all proxy restrictions by setting the environment variable:
@@ -639,7 +691,7 @@ If you're running Dashy in a fully isolated/private environment and you've delib
DANGEROUSLY_DISABLE_PROXY_RESTRICTIONS=true
```
-The variable is named so loudly because flipping it on a Dashy instance that's exposed to anything other than fully trusted users re-opens the SSRF surface — anyone who can hit `/cors-proxy` can then use Dashy as a relay to reach internal services. **Don't set it on cloud-hosted or internet-exposed deployments.**
+The variable is named so loudly because flipping it on a Dashy instance that's exposed to anything other than fully trusted users re-opens the SSRF surface - anyone who can hit `/cors-proxy` can then use Dashy as a relay to reach internal services. **Don't set it on cloud-hosted or internet-exposed deployments.**
Note that this is an all-or-nothing escape hatch, not a per-host allowlist. If you only need to reach one specific host that's currently blocked, please open a feature request describing the use case.
diff --git a/src/App.vue b/src/App.vue
index 58954cc6..7f326e89 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -83,8 +83,7 @@ export default {
return this.$store.state.criticalError;
},
subPageClassName() {
- const currentSubPage = this.$store.state.currentConfigInfo;
- return (currentSubPage && currentSubPage.pageId) ? currentSubPage.pageId : '';
+ return this.$store.state.currentConfigInfo?.confId || '';
},
topLevelStyleModifications() {
const vc = this.visibleComponents;
diff --git a/src/components/LinkItems/Section.vue b/src/components/LinkItems/Section.vue
index 220631ae..f5930970 100644
--- a/src/components/LinkItems/Section.vue
+++ b/src/components/LinkItems/Section.vue
@@ -23,10 +23,9 @@
:class="`there-are-items ${isGridLayout? 'item-group-grid': ''} inner-size-${itemSize}`"
:style="gridStyle" :id="`section-${groupId}`"
> <!-- Show for each item -->
- <template v-for="(item) in sortedItems">
+ <template v-for="(item) in sortedItems" :key="item.id">
<SubItemGroup
v-if="item.subItems"
- :key="item.id"
:itemId="item.id"
:title="item.title"
:subItems="item.subItems"
@@ -35,7 +34,6 @@
<Item
v-else
:item="item"
- :key="item.id"
:itemSize="itemSize"
:parentSectionTitle="title"
@itemClicked="$emit('itemClicked')"
@@ -110,7 +108,7 @@ import IframeModal from '@/components/LinkItems/IframeModal.vue';
import EditSection from '@/components/InteractiveEditor/EditSection.vue';
import ContextMenu from '@/components/LinkItems/SectionContextMenu.vue';
import ErrorHandler from '@/utils/logging/ErrorHandler';
-import { makePageSlug } from '@/utils/config/ConfigHelpers';
+import { makeRoutePath, viewFromPath } from '@/utils/config/ConfigHelpers';
import StoreKeys from '@/utils/StoreMutations';
import {
sortOrder as defaultSortOrder,
@@ -247,13 +245,16 @@ export default {
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value);
},
- /* Navigate to the section's single-section view page */
+ /* Navigate to the section's single-section view. Uses loaded confId from state
+ * (not the URL) so clicks recover cleanly if the current URL is mid-error. */
navigateToSection() {
if (!this.title) {
ErrorHandler('Cannot open section without a valid name');
return;
}
- router.push({ path: makePageSlug(this.title, 'home') });
+ const view = viewFromPath(this.$route.path);
+ const confId = this.$store.state.currentConfigInfo?.confId || null;
+ router.push({ path: makeRoutePath(view, confId, this.title) });
this.closeContextMenu();
},
/* Toggle sections collapse state */
diff --git a/src/components/MinimalView/MinimalSection.vue b/src/components/MinimalView/MinimalSection.vue
index 4c0c0746..a221e114 100644
--- a/src/components/MinimalView/MinimalSection.vue
+++ b/src/components/MinimalView/MinimalSection.vue
@@ -1,10 +1,9 @@
<template>
<div :class="`minimal-section-inner ${selected ? 'selected' : ''} ${showAll ? 'show-all': ''}`">
<div class="section-items" v-if="items && (selected || showAll)">
- <template v-for="(item) in items">
+ <template v-for="(item) in items" :key="item.id">
<SubItemGroup
v-if="item.subItems"
- :key="item.id"
:itemId="item.id"
:title="item.title"
:subItems="item.subItems"
@@ -13,7 +12,6 @@
<Item
v-else
:item="item"
- :key="item.id"
:itemSize="itemSize"
:parentSectionTitle="title"
@itemClicked="$emit('itemClicked')"
@@ -49,7 +47,7 @@ import Item from '@/components/LinkItems/Item.vue';
import WidgetBase from '@/components/Widgets/WidgetBase';
import SubItemGroup from '@/components/LinkItems/SubItemGroup.vue';
import IframeModal from '@/components/LinkItems/IframeModal.vue';
-import { makePageSlug } from '@/utils/config/ConfigHelpers';
+import { makeRoutePath, viewFromPath } from '@/utils/config/ConfigHelpers';
export default {
name: 'ItemGroup',
@@ -101,9 +99,12 @@ export default {
if (interval < 1) interval = 0;
return interval;
},
- /* Navigate to the section's single-section view page */
+ /* Navigate to the section's single-section view page, staying within the current
+ * view and loaded sub-page context */
navigateToSection() {
- router.push({ path: makePageSlug(this.title, 'home') });
+ const view = viewFromPath(this.$route.path);
+ const confId = this.$store.state.currentConfigInfo?.confId || null;
+ router.push({ path: makeRoutePath(view, confId, this.title) });
},
},
};
diff --git a/src/components/PageStrcture/Nav.vue b/src/components/PageStrcture/Nav.vue
index 019cecc9..748728e6 100644
--- a/src/components/PageStrcture/Nav.vue
+++ b/src/components/PageStrcture/Nav.vue
@@ -28,7 +28,7 @@
<script>
import IconBurger from '@/assets/interface-icons/burger-menu.svg';
-import { makePageSlug } from '@/utils/config/ConfigHelpers';
+import { makePageSlug, viewFromPath } from '@/utils/config/ConfigHelpers';
import { checkPageVisibility } from '@/utils/CheckPageVisibility';
export default {
@@ -44,11 +44,13 @@ export default {
isMobile: false,
}),
computed: {
- /* Get links to sub-pages, and combine with nav-links */
+ /* Get links to sub-pages, and combine with nav-links. Sub-page links honor the
+ * current view (home/minimal/workspace) so users stay in the view they chose. */
allLinks() {
+ const view = viewFromPath(this.$route.path);
const subPages = this.$store.getters.pages.filter((page) => checkPageVisibility(page))
.map((subPage) => ({
- path: makePageSlug(subPage.name, 'home'),
+ path: makePageSlug(subPage.name, view),
title: subPage.name,
}));
const navLinks = this.links || [];
diff --git a/src/components/Settings/ViewSwitcher.vue b/src/components/Settings/ViewSwitcher.vue
index 8add52e0..33b56b61 100644
--- a/src/components/Settings/ViewSwitcher.vue
+++ b/src/components/Settings/ViewSwitcher.vue
@@ -2,17 +2,17 @@
<div class="view-switcher">
<ul>
<li>
- <router-link :to="`/home/${subPagePath}`">
+ <router-link :to="pathFor('home')">
<IconHome /><span>{{ $t('alternate-views.default') }}</span>
</router-link>
</li>
<li>
- <router-link :to="`/minimal/${subPagePath}`">
+ <router-link :to="pathFor('minimal')">
<IconMinimalView /><span>{{ $t('alternate-views.minimal') }}</span>
</router-link>
</li>
<li>
- <router-link :to="`/workspace/${subPagePath}`">
+ <router-link :to="pathFor('workspace')">
<IconWorkspaceView /><span>{{ $t('alternate-views.workspace') }}</span>
</router-link>
</li>
@@ -24,6 +24,7 @@
import IconHome from '@/assets/interface-icons/application-home.svg';
import IconWorkspaceView from '@/assets/interface-icons/open-workspace.svg';
import IconMinimalView from '@/assets/interface-icons/application-minimal.svg';
+import { makeRoutePath, resolveRouteIntent } from '@/utils/config/ConfigHelpers';
export default {
components: {
@@ -31,9 +32,11 @@ export default {
IconWorkspaceView,
IconMinimalView,
},
- computed: {
- subPagePath() {
- return this.$route.path.split('/').pop() || '';
+ methods: {
+ /* Make URL to the given view. Includes current sub-page, and section when supported */
+ pathFor(view) {
+ const { pageId, sectionSlug } = resolveRouteIntent(this.$route, this.$store);
+ return makeRoutePath(view, pageId, sectionSlug);
},
},
};
diff --git a/src/components/Workspace/SideBar.vue b/src/components/Workspace/SideBar.vue
index cd626987..cabf9376 100644
--- a/src/components/Workspace/SideBar.vue
+++ b/src/components/Workspace/SideBar.vue
@@ -18,12 +18,12 @@
/>
</transition>
</div>
- <!-- Show links for switching back to Home / Minimal views -->
+ <!-- Show links for switching back to Home / Minimal views, preserving sub-page -->
<div class="switch-view-buttons">
- <router-link to="/home/">
+ <router-link :to="pathFor('home')">
<IconHome class="view-icon" v-tooltip="$t('alternate-views.default')" />
</router-link>
- <router-link to="/minimal/">
+ <router-link :to="pathFor('minimal')">
<IconMinimalView class="view-icon" v-tooltip="$t('alternate-views.minimal')" />
</router-link>
</div>
@@ -37,6 +37,7 @@ import SideBarSection from '@/components/Workspace/SideBarSection.vue';
import IconHome from '@/assets/interface-icons/application-home.svg';
import IconMinimalView from '@/assets/interface-icons/application-minimal.svg';
import { checkItemVisibility } from '@/utils/CheckItemVisibility';
+import { makeRoutePath, resolveRouteIntent } from '@/utils/config/ConfigHelpers';
export default {
name: 'SideBar',
@@ -104,6 +105,11 @@ export default {
return allTiles.filter((tile) => checkItemVisibility(tile)
&& !tile.displayData?.hideFromWorkspace);
},
+ /* Build a URL for the given view, preserving the current sub-page and section */
+ pathFor(view) {
+ const { pageId, sectionSlug } = resolveRouteIntent(this.$route, this.$store);
+ return makeRoutePath(view, pageId, sectionSlug);
+ },
},
mounted() {
// Initialize isOpen array based on filteredSections length
diff --git a/src/mixins/HomeMixin.js b/src/mixins/HomeMixin.js
index 660e668f..62d8751a 100644
--- a/src/mixins/HomeMixin.js
+++ b/src/mixins/HomeMixin.js
@@ -6,13 +6,11 @@ import Defaults, { localStorageKeys, iconCdns } from '@/utils/config/defaults';
import Keys from '@/utils/StoreMutations';
import { searchTiles } from '@/utils/Search';
import { checkItemVisibility } from '@/utils/CheckItemVisibility';
+import { resolveRouteIntent, PAGE_STATUS } from '@/utils/config/ConfigHelpers';
import ThemingMixin from '@/mixins/ThemingMixin';
const HomeMixin = {
mixins: [ThemingMixin],
- props: {
- subPageInfo: Object,
- },
computed: {
sections() {
return this.$store.getters.sections;
@@ -53,17 +51,22 @@ const HomeMixin = {
this.loadUpConfig();
},
methods: {
- /* When page loaded / sub-page changed, initiate config fetch */
+ /* When page loaded / sub-page changed, initiate config fetch.
+ * For ROOT / LEGACY_SECTION intent the store loads the root config
+ * for KNOWN the store loads the matching sub-config
+ * for UNKNOWN the store triggers the critical error modal */
async loadUpConfig() {
const subPage = this.determineConfigFile();
+ const current = this.$store.state.currentConfigInfo?.confId || null;
+ if ((subPage || null) === current) return; // Already on this config, no reload
await this.$store.dispatch(Keys.INITIALIZE_CONFIG, subPage);
},
- /* Based on the current route, get which config to display, null will use default */
+ /* Resolve which sub-config the current route targets.
+ * Returns a page id from makePageName, or null for the root config */
determineConfigFile() {
- const pagePath = this.$route.path;
- const isSubPage = new RegExp((/(home|workspace|minimal)\/[a-zA-Z0-9-]+/g)).test(pagePath);
- const subPageName = isSubPage ? pagePath.split('/').pop() : null;
- return subPageName;
+ const { status, pageId } = resolveRouteIntent(this.$route, this.$store);
+ if (status === PAGE_STATUS.ROOT || status === PAGE_STATUS.LEGACY_SECTION) return null;
+ return pageId; // KNOWN -> load sub-config; UNKNOWN -> store raises critical error
},
setTheme() {
this.initializeTheme();
diff --git a/src/router.js b/src/router.js
index 8eb360a5..512fc5f3 100644
--- a/src/router.js
+++ b/src/router.js
@@ -49,6 +49,25 @@ const makeMetaTags = (defaultTitle) => {
return { title, metaTags: metaTagData };
};
+/* Build the canonical /<view>/:page?/:section? routes for a given view + component.
+ * withSection=false for workspace (no single-section view yet). */
+const makeViewRoutes = (basePath, viewName, component, title, withSection = true) => {
+ const meta = makeMetaTags(title);
+ const routes = [
+ { path: basePath, name: viewName, component, meta },
+ { path: `${basePath}/:page`, name: `${viewName}-page`, component, meta },
+ ];
+ if (withSection) {
+ routes.push({
+ path: `${basePath}/:page/:section`,
+ name: `${viewName}-section`,
+ component,
+ meta,
+ });
+ }
+ return routes;
+};
+
/* Routing mode, can be either 'hash', 'history' or 'abstract' */
const mode = import.meta.env.VITE_APP_ROUTING_MODE || 'history';
@@ -61,37 +80,27 @@ const history = mode === 'hash'
const router = createRouter({
history,
routes: [
- // ...makeMultiPageRoutes(pages),
{ // The default view can be customized by the user
path: '/',
name: `landing-page-${startingView}`,
component: getStartingComponent(),
meta: makeMetaTags('Home Page'),
},
- { // Default home page
- path: routePaths.home,
- name: 'home',
- component: Home,
- meta: makeMetaTags('Home Page'),
- },
- { // View only single section
- path: `${routePaths.home}/:section`,
- name: 'home-section',
- component: Home,
- meta: makeMetaTags('Home Page'),
- },
- { // Workspace view page
- path: routePaths.workspace,
- name: 'workspace',
- component: () => import('./views/Workspace.vue'),
- meta: makeMetaTags('Workspace'),
- },
- { // Minimal view page
- path: routePaths.minimal,
- name: 'minimal',
- component: () => import('./views/Minimal.vue'),
- meta: makeMetaTags('Start Page'),
- },
+ // Canonical /<view>/:page?/:section? routes for each view
+ ...makeViewRoutes(routePaths.home, 'home', Home, 'Home Page'),
+ ...makeViewRoutes(
+ routePaths.minimal,
+ 'minimal',
+ () => import('./views/Minimal.vue'),
+ 'Start Page',
+ ),
+ ...makeViewRoutes(
+ routePaths.workspace,
+ 'workspace',
+ () => import('./views/Workspace.vue'),
+ 'Workspace',
+ false,
+ ),
{ // The login page
path: routePaths.login,
name: 'login',
diff --git a/src/store.js b/src/store.js
index 2b1bf481..8216c2d8 100644
--- a/src/store.js
+++ b/src/store.js
@@ -192,10 +192,10 @@ const store = createStore({
},
},
mutations: {
- /* Set the master config */
+ /* Cache the raw root config so sub-page navigations don't re-fetch the main YAML */
[SET_ROOT_CONFIG](state, config) {
if (!config.appConfig) config.appConfig = {};
- state.config = config;
+ state.rootConfig = config;
},
/* The config to display and edit. Will differ from ROOT_CONFIG when using multi-page */
[SET_CONFIG](state, config) {
@@ -425,27 +425,35 @@ const store = createStore({
* override certain fields (appConfig, pages) and update config
*/
async [INITIALIZE_CONFIG]({ commit, state }, subConfigId) {
- const rootConfig = state.rootConfig || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG);
- // Apply root-level local overrides to a clone so state.rootConfig stays as the raw YAML
- const root = { ...rootConfig };
- const rootUsingLocal = applyLocalOverrides(root);
+ try {
+ const rootConfig = state.rootConfig
+ || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG);
+ // Needs deep clone, so overrides can't mutate cached root
+ const root = JSON.parse(JSON.stringify(rootConfig));
+ const rootUsingLocal = applyLocalOverrides(root);
- if (!subConfigId) { // Root page: commit the overridden root config directly
- commit(SET_CONFIG, root);
- commit(SET_CURRENT_CONFIG_INFO, {});
- commit(SET_IS_USING_LOCAL_CONFIG, rootUsingLocal);
- return root;
- }
+ if (!subConfigId) { // Root page: commit the overridden root config directly
+ commit(SET_CONFIG, root);
+ commit(SET_CURRENT_CONFIG_INFO, {});
+ commit(SET_IS_USING_LOCAL_CONFIG, rootUsingLocal);
+ return root;
+ }
- const subConfigPath = formatConfigPath(root?.pages?.find(
- (page) => makePageName(page.name) === subConfigId,
- )?.path);
- if (!subConfigPath) {
- commit(CRITICAL_ERROR_MSG, `Unable to find config for '${subConfigId}'`);
- return { ...emptyConfig };
- }
- try {
- const response = await request.get(subConfigPath, makeBasicAuthHeaders());
+ const subConfigPath = formatConfigPath(root?.pages?.find(
+ (page) => page?.name && makePageName(page.name) === subConfigId,
+ )?.path);
+ if (!subConfigPath) {
+ commit(CRITICAL_ERROR_MSG, `Unable to find config for '${subConfigId}'`);
+ return { ...emptyConfig };
+ }
+ let response;
+ try {
+ response = await request.get(subConfigPath, makeBasicAuthHeaders());
+ } catch (fetchErr) {
+ commit(CRITICAL_ERROR_MSG, `Unable to load config from '${subConfigPath}'`);
+ ErrorHandler(`Sub-config load failed: ${subConfigPath}`, fetchErr);
+ return { ...emptyConfig };
+ }
let configContent;
try {
configContent = yaml.load(response.data) || {};
@@ -453,21 +461,19 @@ const store = createStore({
commit(CRITICAL_ERROR_MSG, `Failed to parse sub-config YAML: ${parseError.message}`);
return { ...emptyConfig };
}
- // Inherit shared fields from the (already overridden) root config
+ // Inherit shared appConfig + pages from root, but override theme per sub-page
const theme = configContent?.appConfig?.theme || root.appConfig?.theme || 'default';
- configContent.appConfig = root.appConfig;
+ configContent.appConfig = { ...root.appConfig, theme };
configContent.pages = root.pages;
- configContent.appConfig.theme = theme;
- // Then apply sub-page local overrides
const subUsingLocal = applyLocalOverrides(configContent, subConfigId);
commit(SET_CONFIG, configContent);
commit(SET_CURRENT_CONFIG_INFO, { confPath: subConfigPath, confId: subConfigId });
commit(SET_IS_USING_LOCAL_CONFIG, subUsingLocal);
return configContent;
- } catch (err) {
- commit(CRITICAL_ERROR_MSG, `Unable to load config from '${subConfigPath}'`);
- ErrorHandler(`Sub-config load failed: ${subConfigPath}`, err);
+ } catch (err) { // If we get here, then somethings really fucked up
+ commit(CRITICAL_ERROR_MSG, `Unexpected error loading config: ${err.message}`);
+ ErrorHandler('INITIALIZE_CONFIG failed', err);
return { ...emptyConfig };
}
},
diff --git a/src/utils/config/ConfigHelpers.js b/src/utils/config/ConfigHelpers.js
index 1272b647..3fedb755 100644
--- a/src/utils/config/ConfigHelpers.js
+++ b/src/utils/config/ConfigHelpers.js
@@ -8,28 +8,96 @@ import {
language as defaultLanguage,
} from '@/utils/config/defaults';
-/* Given a page name, converts to lowercase, removes special characters and extension */
+/* Page id used in URLs to mean "the root config" */
+export const RESERVED_ROOT = 'main';
+
+/* Metadata for each view in the canonical /<view>/:page?/:section? URL scheme */
+export const VIEW_META = {
+ home: { supportsSection: true },
+ minimal: { supportsSection: true },
+ workspace: { supportsSection: false },
+};
+
+/* How a URL's :page segment resolves against the current config */
+export const PAGE_STATUS = Object.freeze({
+ ROOT: 'root', // no :page, or :page === RESERVED_ROOT
+ KNOWN: 'known', // matches a real sub-page in config.pages
+ LEGACY_SECTION: 'legacy', // one-segment URL naming a section of the root config
+ UNKNOWN: 'unknown', // no match, store raises a critical error
+});
+
+/* Given a page or section name, produces a deterministic URL slug.
+ * - NFC-normalizes, lowercase, replaces whitespace with -, strips extension
+ * - Drops most punctuation/symbols, except unicode alphanumeric + marks */
export const makePageName = (pageName) => {
if (!pageName) return 'unnamed-page';
- return pageName
+ const cleaned = String(pageName)
+ .normalize('NFC')
.toLowerCase()
- .replaceAll(' ', '-')
- .replace('.yml', '')
- .replace(/[^\w\s-]/gi, '');
+ .replace(/\.yml$/i, '')
+ .replace(/\s+/g, '-')
+ .replace(/[\uFE00-\uFE0F]|[\u{E0100}-\u{E01EF}]/gu, '')
+ .replace(/[^\p{L}\p{N}\p{M}_-]/gu, '')
+ .replace(/^-+|-+$/g, '');
+ if (!cleaned) return 'unnamed-page';
+ if (cleaned === RESERVED_ROOT) return `${RESERVED_ROOT}-page`;
+ return cleaned;
+};
+
+/* Build a canonical Dashy route: /<view>[/<pageId-or-main>[/<sectionSlug>]]
+ * pageId is slugified sub-config id or null for root
+ * If section is present, then page ID is also needed, defaults to RESERVED_ROOT
+ * Can drop the section if the page type (e.g. workspace) doesn't support sec view */
+export const makeRoutePath = (view, pageId, sectionName) => {
+ const resolvedView = VIEW_META[view] ? view : 'home';
+ const base = `/${resolvedView}`;
+ if (sectionName && VIEW_META[resolvedView].supportsSection) {
+ return `${base}/${pageId || RESERVED_ROOT}/${makePageName(sectionName)}`;
+ }
+ if (pageId) return `${base}/${pageId}`;
+ return base;
};
-/* For a given sub-page, and page type, return the URL */
-export const makePageSlug = (pageName, pageType) => {
- const formattedName = makePageName(pageName);
- return `/${pageType}/${formattedName}`;
+/* Convenience wrapper: turn a raw page name into a view URL (e.g. nav links) */
+export const makePageSlug = (pageName, view) => makeRoutePath(view, makePageName(pageName));
+
+/* Extract the view segment from a path, defaulting to 'home' */
+export const viewFromPath = (path) => {
+ const seg = (path || '').split('/').filter(Boolean)[0];
+ return VIEW_META[seg] ? seg : 'home';
+};
+
+/* Parse a Vue Router route into { view, pageId, sectionSlug, status } */
+export const resolveRouteIntent = (route, store) => {
+ const view = viewFromPath(route?.path);
+ const { page: rawPage, section: rawSection } = route?.params || {};
+ const sectionSlug = rawSection ? makePageName(rawSection) : null;
+
+ if (!rawPage || rawPage === RESERVED_ROOT) {
+ return { view, pageId: null, sectionSlug, status: PAGE_STATUS.ROOT };
+ }
+ const pageId = makePageName(rawPage);
+ const pages = store?.getters?.pages || [];
+ if (pages.some((p) => p?.name && makePageName(p.name) === pageId)) {
+ return { view, pageId, sectionSlug, status: PAGE_STATUS.KNOWN };
+ }
+ // Legacy one-segment URL naming a root section (only when no explicit :section)
+ if (!rawSection) {
+ const rootSections = store?.state?.rootConfig?.sections || [];
+ if (rootSections.some((s) => s?.name && makePageName(s.name) === pageId)) {
+ return { view, pageId: null, sectionSlug: pageId, status: PAGE_STATUS.LEGACY_SECTION };
+ }
+ }
+ return { view, pageId, sectionSlug, status: PAGE_STATUS.UNKNOWN };
};
/* Put fetch path for additional configs in correct format */
export const formatConfigPath = (configPath) => {
if (!configPath) return null;
if (configPath.includes('http')) return configPath;
- if (configPath.substring(0, 1) !== '/') return `/${configPath}`;
- return configPath;
+ const stripped = configPath.replace(/^\.\//, '');
+ if (stripped.substring(0, 1) !== '/') return `/${stripped}`;
+ return stripped;
};
/**
diff --git a/src/utils/config/defaults.js b/src/utils/config/defaults.js
index 8c06ca20..4d02d846 100644
--- a/src/utils/config/defaults.js
+++ b/src/utils/config/defaults.js
@@ -28,9 +28,9 @@ const defaults = {
openingMethod: 'newtab',
/* The page paths for each route within the app for the router */
routePaths: {
- home: '/home/:config?/',
- minimal: '/minimal/:config?/',
- workspace: '/workspace/:config?/',
+ home: '/home',
+ minimal: '/minimal',
+ workspace: '/workspace',
about: '/about',
login: '/login',
download: '/download',
diff --git a/src/views/Home.vue b/src/views/Home.vue
index efbbb5f9..5c440adb 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -13,7 +13,7 @@
/>
<!-- Show back button, when on single-section view -->
<div v-if="singleSectionView">
- <router-link to="/home" class="back-to-all-link">
+ <router-link :to="backToAllPath" class="back-to-all-link">
<BackIcon />
<span>Back to All</span>
</router-link>
@@ -65,7 +65,9 @@ import AddNewSection from '@/components/InteractiveEditor/AddNewSectionLauncher.
import NotificationThing from '@/components/Settings/LocalConfigWarning.vue';
import StoreKeys from '@/utils/StoreMutations';
import { modalNames } from '@/utils/config/defaults';
-import { makePageName } from '@/utils/config/ConfigHelpers';
+import {
+ makePageName, makeRoutePath, resolveRouteIntent, viewFromPath,
+} from '@/utils/config/ConfigHelpers';
import ErrorHandler from '@/utils/logging/ErrorHandler';
import BackIcon from '@/assets/interface-icons/back-arrow.svg';
@@ -89,7 +91,15 @@ export default {
}),
computed: {
singleSectionView() {
- return this.findSingleSection(this.$store.getters.sections, this.$route.params.section);
+ const { sectionSlug } = resolveRouteIntent(this.$route, this.$store);
+ if (!sectionSlug) return undefined;
+ return this.findSingleSection(this.$store.getters.sections, sectionSlug);
+ },
+ /* Back link from single-section view */
+ backToAllPath() {
+ const view = viewFromPath(this.$route.path);
+ const confId = this.$store.state.currentConfigInfo?.confId || null;
+ return makeRoutePath(view, confId);
},
/* Get class for num columns, if specified by user */
colCount() {
diff --git a/src/views/Minimal.vue b/src/views/Minimal.vue
index 9ec125fe..b466cdaa 100644
--- a/src/views/Minimal.vue
+++ b/src/views/Minimal.vue
@@ -58,6 +58,8 @@ import MinimalSection from '@/components/MinimalView/MinimalSection.vue';
import MinimalHeading from '@/components/MinimalView/MinimalHeading.vue';
import MinimalSearch from '@/components/MinimalView/MinimalSearch.vue';
import ConfigLauncher from '@/components/Settings/ConfigLauncher';
+import { makePageName, resolveRouteIntent } from '@/utils/config/ConfigHelpers';
+import ErrorHandler from '@/utils/logging/ErrorHandler';
export default {
name: 'home',
@@ -77,11 +79,26 @@ export default {
searchValue() {
this.tabbedView = !this.searchValue || this.searchValue.length === 0;
},
+ /* Keep the selected section in sync with the URL (/minimal/:page/:section) */
+ '$route.params.section': {
+ handler() { this.syncSelectedFromRoute(); },
+ immediate: true,
+ },
+ sections() { this.syncSelectedFromRoute(); },
},
methods: {
sectionSelected(index) {
this.selectedSection = index;
},
+ /* If section slug present in the URL, then auto-select it if it exists */
+ syncSelectedFromRoute() {
+ if (!this.sections || !this.sections.length) return;
+ const { sectionSlug } = resolveRouteIntent(this.$route, this.$store);
+ if (!sectionSlug) { this.selectedSection = 0; return; }
+ const idx = this.sections.findIndex((s) => makePageName(s.name || '') === sectionSlug);
+ if (idx >= 0) { this.selectedSection = idx; return; }
+ ErrorHandler(`No section named '${sectionSlug}' was found in the current config`);
+ },
/* Clears input field, once a searched item is opened */
finishedSearching() {
if (this.$refs.filterComp) this.$refs.filterComp.clearMinFilterInput();
diff --git a/tests/unit/config-helpers.test.js b/tests/unit/config-helpers.test.js
index 9bd457a3..5a72bb14 100644
--- a/tests/unit/config-helpers.test.js
+++ b/tests/unit/config-helpers.test.js
@@ -2,6 +2,11 @@ import { describe, it, expect } from 'vitest';
import {
makePageName,
makePageSlug,
+ makeRoutePath,
+ viewFromPath,
+ resolveRouteIntent,
+ PAGE_STATUS,
+ RESERVED_ROOT,
formatConfigPath,
componentVisibility,
getCustomKeyShortcuts,
@@ -35,6 +40,57 @@ describe('ConfigHelpers - makePageName', () => {
it('handles empty string', () => {
expect(makePageName('')).toBe('unnamed-page');
});
+
+ it('trims leading dash left by stripped emoji', () => {
+ expect(makePageName('🌐 Command Center')).toBe('command-center');
+ });
+
+ it('trims trailing dashes', () => {
+ expect(makePageName('My Page-')).toBe('my-page');
+ });
+
+ it('falls back to unnamed-page when all chars are stripped', () => {
+ expect(makePageName('🌐🚀')).toBe('unnamed-page');
+ });
+
+ it(`reserves "${RESERVED_ROOT}" so user pages cannot shadow the root sentinel`, () => {
+ expect(makePageName('Main')).toBe(`${RESERVED_ROOT}-page`);
+ expect(makePageName('main')).toBe(`${RESERVED_ROOT}-page`);
+ expect(makePageName(' MAIN ')).toBe(`${RESERVED_ROOT}-page`);
+ });
+
+ it('is idempotent — slugging an already-slug string returns the same slug', () => {
+ const slug = makePageName('🌐 Command Center');
+ expect(makePageName(slug)).toBe(slug);
+ });
+
+ it('preserves accented Latin so names round-trip (Vue Router percent-encodes the URL)', () => {
+ expect(makePageName('Sección Configuración')).toBe('sección-configuración');
+ expect(makePageName('Größe')).toBe('größe');
+ });
+
+ it('preserves CJK, Cyrillic, and Arabic names', () => {
+ expect(makePageName('中文')).toBe('中文');
+ expect(makePageName('日本語 工具')).toBe('日本語-工具');
+ expect(makePageName('Привет')).toBe('привет');
+ expect(makePageName('مرحبا')).toBe('مرحبا');
+ });
+
+ it('still strips emoji, punctuation and symbols in mixed-script names', () => {
+ expect(makePageName('🌐 Command Center!')).toBe('command-center');
+ expect(makePageName('⚙️ 设置')).toBe('设置');
+ expect(makePageName('$100 Club')).toBe('100-club');
+ });
+
+ it('NFC-normalizes so composed and decomposed forms produce the same slug', () => {
+ // 'é' as one codepoint (U+00E9) vs 'e' + combining acute (U+0065 U+0301)
+ expect(makePageName('café')).toBe(makePageName('cafe\u0301'));
+ });
+
+ it('collapses whitespace-only names to unnamed-page', () => {
+ expect(makePageName(' ')).toBe('unnamed-page');
+ expect(makePageName('\t\n')).toBe('unnamed-page');
+ });
});
describe('ConfigHelpers - makePageSlug', () => {
@@ -43,7 +99,206 @@ describe('ConfigHelpers - makePageSlug', () => {
});
it('handles page names with special chars', () => {
- expect(makePageSlug('Config! Page', 'admin')).toBe('/admin/config-page');
+ expect(makePageSlug('Config! Page', 'home')).toBe('/home/config-page');
+ });
+
+ it('falls back to home when view is unknown', () => {
+ expect(makePageSlug('My Page', 'bogus')).toBe('/home/my-page');
+ });
+});
+
+describe('ConfigHelpers - makeRoutePath', () => {
+ it('returns /<view> for root, no sub-page, no section', () => {
+ expect(makeRoutePath('home')).toBe('/home');
+ expect(makeRoutePath('minimal')).toBe('/minimal');
+ expect(makeRoutePath('workspace')).toBe('/workspace');
+ });
+
+ it('returns /<view>/:page for a sub-page without a section', () => {
+ expect(makeRoutePath('home', 'homelab')).toBe('/home/homelab');
+ expect(makeRoutePath('minimal', 'homelab')).toBe('/minimal/homelab');
+ });
+
+ it('nests section under sub-page id', () => {
+ expect(makeRoutePath('home', 'homelab', 'My Tools')).toBe('/home/homelab/my-tools');
+ });
+
+ it('uses RESERVED_ROOT sentinel for a section on the root config', () => {
+ expect(makeRoutePath('home', null, 'My Tools')).toBe(`/home/${RESERVED_ROOT}/my-tools`);
+ });
+
+ it('slugifies section names with emoji', () => {
+ expect(makeRoutePath('minimal', 'dev', '🚀 Tools')).toBe('/minimal/dev/tools');
+ });
+
+ it('defaults to home view when view arg is invalid', () => {
+ expect(makeRoutePath('bogus', 'homelab')).toBe('/home/homelab');
+ });
+});
+
+describe('ConfigHelpers - viewFromPath', () => {
+ it('extracts the view segment from a path', () => {
+ expect(viewFromPath('/home/homelab')).toBe('home');
+ expect(viewFromPath('/minimal/homelab/tools')).toBe('minimal');
+ expect(viewFromPath('/workspace')).toBe('workspace');
+ });
+
+ it('defaults to home for root or unknown paths', () => {
+ expect(viewFromPath('/')).toBe('home');
+ expect(viewFromPath('/about')).toBe('home');
+ expect(viewFromPath('')).toBe('home');
+ });
+});
+
+describe('ConfigHelpers - resolveRouteIntent', () => {
+ const fakeStore = ({ pages = [], rootSections = [] } = {}) => ({
+ getters: { pages },
+ state: { rootConfig: { sections: rootSections } },
+ });
+ const route = (path, params = {}) => ({ path, params });
+
+ it('classifies /<view> as ROOT', () => {
+ const out = resolveRouteIntent(route('/home', {}), fakeStore());
+ expect(out).toEqual({
+ view: 'home', pageId: null, sectionSlug: null, status: PAGE_STATUS.ROOT,
+ });
+ });
+
+ it('classifies /<view>/main as ROOT (sentinel)', () => {
+ const out = resolveRouteIntent(route('/minimal/main', { page: 'main' }), fakeStore());
+ expect(out.status).toBe(PAGE_STATUS.ROOT);
+ expect(out.pageId).toBeNull();
+ expect(out.view).toBe('minimal');
+ });
+
+ it('classifies /<view>/main/:section as ROOT with sectionSlug', () => {
+ const out = resolveRouteIntent(
+ route('/home/main/tools', { page: 'main', section: 'Tools' }),
+ fakeStore(),
+ );
+ expect(out.status).toBe(PAGE_STATUS.ROOT);
+ expect(out.pageId).toBeNull();
+ expect(out.sectionSlug).toBe('tools');
+ });
+
+ it('classifies a known sub-page as KNOWN', () => {
+ const store = fakeStore({ pages: [{ name: '🏠 Homelab' }] });
+ const out = resolveRouteIntent(
+ route('/home/homelab/media', { page: 'homelab', section: 'Media' }),
+ store,
+ );
+ expect(out.status).toBe(PAGE_STATUS.KNOWN);
+ expect(out.pageId).toBe('homelab');
+ expect(out.sectionSlug).toBe('media');
+ });
+
+ it('forgives a legacy /<view>/<root-section> URL as LEGACY_SECTION', () => {
+ const store = fakeStore({ rootSections: [{ name: 'Getting Started' }] });
+ const out = resolveRouteIntent(
+ route('/home/getting-started', { page: 'getting-started' }),
+ store,
+ );
+ expect(out.status).toBe(PAGE_STATUS.LEGACY_SECTION);
+ expect(out.pageId).toBeNull();
+ expect(out.sectionSlug).toBe('getting-started');
+ });
+
+ it('does NOT fall through to legacy when the URL has an explicit :section', () => {
+ const store = fakeStore({ rootSections: [{ name: 'Getting Started' }] });
+ const out = resolveRouteIntent(
+ route('/home/getting-started/whatever', {
+ page: 'getting-started', section: 'whatever',
+ }),
+ store,
+ );
+ expect(out.status).toBe(PAGE_STATUS.UNKNOWN);
+ });
+
+ it('returns UNKNOWN for a page that matches neither a sub-page nor a root section', () => {
+ const store = fakeStore({ pages: [{ name: 'Homelab' }], rootSections: [{ name: 'Tools' }] });
+ const out = resolveRouteIntent(
+ route('/home/bogus', { page: 'bogus' }),
+ store,
+ );
+ expect(out.status).toBe(PAGE_STATUS.UNKNOWN);
+ expect(out.pageId).toBe('bogus');
+ });
+
+ it('normalizes raw params — /home/-Homelab resolves to KNOWN homelab', () => {
+ const store = fakeStore({ pages: [{ name: 'Homelab' }] });
+ const out = resolveRouteIntent(
+ route('/home/-Homelab', { page: '-Homelab' }),
+ store,
+ );
+ expect(out.status).toBe(PAGE_STATUS.KNOWN);
+ expect(out.pageId).toBe('homelab');
+ });
+
+ it('resolves a CJK page name (Vue Router hands us the decoded param)', () => {
+ const store = fakeStore({ pages: [{ name: '中文' }] });
+ const out = resolveRouteIntent(
+ route('/home/中文/工具', { page: '中文', section: '工具' }),
+ store,
+ );
+ expect(out.status).toBe(PAGE_STATUS.KNOWN);
+ expect(out.pageId).toBe('中文');
+ expect(out.sectionSlug).toBe('工具');
+ });
+
+ it('safely accepts undefined route or store', () => {
+ const out = resolveRouteIntent(undefined, undefined);
+ expect(out.view).toBe('home');
+ expect(out.status).toBe(PAGE_STATUS.ROOT);
+ });
+});
+
+describe('ConfigHelpers - makeRoutePath (view capability)', () => {
+ it('drops the section when the target view does not support section URLs', () => {
+ // workspace has supportsSection: false, so /workspace/homelab/tools collapses
+ expect(makeRoutePath('workspace', 'homelab', 'tools')).toBe('/workspace/homelab');
+ });
+
+ it('keeps the section for views that support it', () => {
+ expect(makeRoutePath('home', 'homelab', 'tools')).toBe('/home/homelab/tools');
+ expect(makeRoutePath('minimal', 'homelab', 'tools')).toBe('/minimal/homelab/tools');
+ });
+});
+
+describe('Integration: view switching preserves page + section', () => {
+ const fakeStore = ({ pages = [], rootSections = [] } = {}) => ({
+ getters: { pages },
+ state: { rootConfig: { sections: rootSections } },
+ });
+ const route = (path, params) => ({ path, params });
+
+ // Mirrors ViewSwitcher.pathFor(view) — the single code path responsible for this
+ const switchTo = (view, r, store) => {
+ const { pageId, sectionSlug } = resolveRouteIntent(r, store);
+ return makeRoutePath(view, pageId, sectionSlug);
+ };
+
+ it('/home/main/support-dashy -> /minimal/main/support-dashy', () => {
+ const store = fakeStore({ rootSections: [{ name: 'Support Dashy' }] });
+ const r = route('/home/main/support-dashy', { page: 'main', section: 'support-dashy' });
+ expect(switchTo('minimal', r, store)).toBe('/minimal/main/support-dashy');
+ });
+
+ it('/home/homelab/media -> /minimal/homelab/media', () => {
+ const store = fakeStore({ pages: [{ name: 'Homelab' }] });
+ const r = route('/home/homelab/media', { page: 'homelab', section: 'media' });
+ expect(switchTo('minimal', r, store)).toBe('/minimal/homelab/media');
+ });
+
+ it('/home/homelab/media -> /workspace/homelab (section dropped for workspace)', () => {
+ const store = fakeStore({ pages: [{ name: 'Homelab' }] });
+ const r = route('/home/homelab/media', { page: 'homelab', section: 'media' });
+ expect(switchTo('workspace', r, store)).toBe('/workspace/homelab');
+ });
+
+ it('legacy /home/getting-started -> /minimal/main/getting-started', () => {
+ const store = fakeStore({ rootSections: [{ name: 'Getting Started' }] });
+ const r = route('/home/getting-started', { page: 'getting-started' });
+ expect(switchTo('minimal', r, store)).toBe('/minimal/main/getting-started');
});
});
@@ -60,6 +315,11 @@ describe('ConfigHelpers - formatConfigPath', () => {
it('keeps absolute paths unchanged', () => {
expect(formatConfigPath('/config.yml')).toBe('/config.yml');
});
+
+ it('strips a leading ./ so relative YAML paths resolve correctly', () => {
+ expect(formatConfigPath('./config.yml')).toBe('/config.yml');
+ expect(formatConfigPath('./sub/config.yml')).toBe('/sub/config.yml');
+ });
});
describe('ConfigHelpers - componentVisibility', () => {