fix(service-layout): sync path on options change

This commit is contained in:
07akioni 2021-02-14 17:05:28 +08:00
parent ab1d9de7f9
commit 3b432881ad
7 changed files with 13 additions and 6 deletions

View File

@ -315,6 +315,8 @@ export const routes = [
{
name: 'site',
path: '/:lang/:theme',
// Keep the wrapper router view, since if not the route won't be initialized
// after them site is mounted (no matched route)
component: Site,
children: [
{

View File

@ -67,9 +67,12 @@ export default defineComponent({
return createItems(props.items)
})
if (route) {
syncValue(route.path)
syncPath(route.path)
watch(toRef(route, 'path'), (path) => {
syncValue(path)
syncPath(path)
})
watch(toRef(props, 'items'), () => {
syncPath(route.path)
})
}
function doUpdateCollapsed (value: boolean): void {
@ -94,11 +97,11 @@ export default defineComponent({
const scrollTo: LayoutRef['scrollTo'] = (...args: any[]): void => {
;(bodyLayoutInstRef.value?.scrollTo as Function)(...args)
}
function syncValue (path?: string, items?: Item[]): void {
function syncPath (path?: string, items?: Item[]): void {
if (items === undefined) items = props.items
for (const item of items) {
if (item.childItems || item.children) {
syncValue(path, item.childItems || item.children)
syncPath(path, item.childItems || item.children)
} else if (item.path === path) {
doUpdateValue(item.name || item.key || '')
return

View File

@ -2,13 +2,15 @@ import * as components from './components'
import { enUS, zhCN } from './locales'
// deprecated
import { NServiceLayout } from './_deprecated/nimbus-service-layout/index'
import { NServiceLayout } from './_deprecated/service-layout/index'
import create from './create'
export default create({
components: [
...Object.keys(components).map((key) => components[key as keyof typeof components]),
...Object.keys(components).map(
(key) => components[key as keyof typeof components]
),
// Deprecated
NServiceLayout
],