Skip to content

Commit

Permalink
ref : 레이아웃 확장성 있게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
lionleeee committed Dec 24, 2024
1 parent 5ad344f commit 4997f66
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/components/layout/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import './Footer.js';
import '../../core/router/RouterOutlet.js';

export default class Layout extends HTMLElement {
static observedAttributes = ['header', 'footer'];

constructor() {
super();
}
Expand All @@ -12,10 +14,12 @@ export default class Layout extends HTMLElement {
}

render() {
const headerTag = this.getAttribute('header') || '';
const footerTag = this.getAttribute('footer') || '';
this.innerHTML = `
<app-header></app-header>
${headerTag ? `<${headerTag}></${headerTag}>` : ''}
<router-outlet></router-outlet>
<app-footer></app-footer>
${footerTag ? `<${footerTag}></${footerTag}>` : ''}
`;
}
}
Expand Down
17 changes: 4 additions & 13 deletions src/core/router/Router.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import CanvasPage from '../../features/canvas/pages/CanvasPage.js';
import Layout from '../../components/layout/Layout.js';
import RouterOutlet from './RouterOutlet.js';

const routes = {
'/': {
component: CanvasPage,
layout: Layout,
},
'*': {
component: CanvasPage,
layout: Layout,
},
};
import { routes } from './RouterConfig.js';

class Router {
static instance = null;
Expand Down Expand Up @@ -43,7 +32,9 @@ class Router {
const app = document.querySelector('#app');
if (route.layout) {
app.innerHTML = '';
const layout = new route.layout();
const layout = new Layout();
layout.setAttribute('header', route.layout.header);
layout.setAttribute('footer', route.layout.footer);
app.appendChild(layout);
}

Expand Down
11 changes: 11 additions & 0 deletions src/core/router/RouterConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import CanvasPage from '../../features/canvas/pages/CanvasPage';

export const routes = {
'*': {
component: CanvasPage,
layout: {
header: 'app-header',
footer: 'app-footer',
},
},
};

0 comments on commit 4997f66

Please sign in to comment.