์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐Ÿš€ JavaScript ๋ผ์šฐํŒ…๊ณผ SPA ๋„ค๋น„๊ฒŒ์ด์…˜ ๊ตฌํ˜„ ์ „๋žต: ํ˜„๋Œ€์ ์ธ ์›น ์•ฑ์„ ์œ„ํ•œ ์™„๋ฒฝ ๊ฐ€์ด๋“œ

๐Ÿš€ JavaScript ๋ผ์šฐํŒ…๊ณผ SPA ๋„ค๋น„๊ฒŒ์ด์…˜ ๊ตฌํ˜„ ์ „๋žต: ํ˜„๋Œ€์ ์ธ ์›น ์•ฑ์„ ์œ„ํ•œ ์™„๋ฒฝ ๊ฐ€์ด๋“œ

์นœ๊ตฌ์ฒ˜๋Ÿผ ์‰ฝ๊ณ  ์žฌ๋ฏธ์žˆ๊ฒŒ ๋ฐฐ์šฐ๋Š” ํ”„๋ก ํŠธ์—”๋“œ ๋„ค๋น„๊ฒŒ์ด์…˜์˜ ๋ชจ๋“  ๊ฒƒ

๐ŸŽฏ ์•ˆ๋…•, ์นœ๊ตฌ! ์˜ค๋Š˜์€ ์ •๋ง ์ค‘์š”ํ•œ ์ฃผ์ œ๋ฅผ ๊ฐ€์ง€๊ณ  ์™”์–ด. ๋ฐ”๋กœ JavaScript ๋ผ์šฐํŒ…๊ณผ SPA ๋„ค๋น„๊ฒŒ์ด์…˜์ด์•ผ. ์š”์ฆ˜ ์›น ๊ฐœ๋ฐœํ•˜๋ฉด์„œ ์ด๊ฑฐ ๋ชจ๋ฅด๋ฉด ์ง„์งœ ๊ณค๋ž€ํ•˜๊ฑฐ๋“ ? ๐Ÿ˜…


๋„ทํ”Œ๋ฆญ์Šค๋‚˜ ์œ ํŠœ๋ธŒ ์“ธ ๋•Œ ํŽ˜์ด์ง€๊ฐ€ ๊นœ๋นก์ด์ง€ ์•Š๊ณ  ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์ „ํ™˜๋˜๋Š” ๊ฑฐ ๋А๊ปด๋ดค์ง€? ๊ทธ๊ฒŒ ๋ฐ”๋กœ SPA(Single Page Application)์˜ ๋งˆ๋ฒ•์ด์•ผ! ์ด ๊ธ€์—์„œ๋Š” ๊ทธ ๋งˆ๋ฒ•์„ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ๋ ค์ค„๊ฒŒ. ์ดˆ๋ณด์ž๋„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ฐจ๊ทผ์ฐจ๊ทผ ์„ค๋ช…ํ•  ํ…Œ๋‹ˆ๊นŒ ๊ฑฑ์ • ๋งˆ! ๐Ÿ’ช

SPA Router Navigation Home About Contact โšก

๐Ÿค” SPA์™€ ๋ผ์šฐํŒ…, ๋„๋Œ€์ฒด ๋ญ๊ธธ๋ž˜?

๋จผ์ € ๊ธฐ๋ณธ ๊ฐœ๋…๋ถ€ํ„ฐ ํ™•์‹คํžˆ ์žก๊ณ  ๊ฐ€์ž! ์ „ํ†ต์ ์ธ ์›น์‚ฌ์ดํŠธ๋Š” ๋งํฌ๋ฅผ ํด๋ฆญํ•  ๋•Œ๋งˆ๋‹ค ์„œ๋ฒ„์—์„œ ์™„์ „ํžˆ ์ƒˆ๋กœ์šด HTML ํŽ˜์ด์ง€๋ฅผ ๋ฐ›์•„์™€. ๊ทธ๋ž˜์„œ ํ™”๋ฉด์ด ๊นœ๋นก์ด๊ณ  ๋กœ๋”ฉ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ์ง€. ๐Ÿ˜ด


ํ•˜์ง€๋งŒ SPA(Single Page Application)๋Š” ๋‹ค๋ฅด๊ฒŒ ์ž‘๋™ํ•ด. ์ฒ˜์Œ ํ•œ ๋ฒˆ๋งŒ ํŽ˜์ด์ง€๋ฅผ ๋กœ๋“œํ•˜๊ณ , ๊ทธ ๋‹ค์Œ๋ถ€ํ„ฐ๋Š” JavaScript๊ฐ€ ํ•„์š”ํ•œ ๋ถ€๋ถ„๋งŒ ๋™์ ์œผ๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” ๊ฑฐ์•ผ. ๋งˆ์น˜ ์ฑ…์˜ ํŽ˜์ด์ง€๋ฅผ ๋„˜๊ธฐ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ!

๐Ÿ“š ํ•ต์‹ฌ ์šฉ์–ด ์ •๋ฆฌ


โ€ข SPA (Single Page Application): ํ•˜๋‚˜์˜ HTML ํŽ˜์ด์ง€์—์„œ JavaScript๋กœ ์ฝ˜ํ…์ธ ๋ฅผ ๋™์ ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜


โ€ข ๋ผ์šฐํŒ… (Routing): URL ๊ฒฝ๋กœ์— ๋”ฐ๋ผ ์ ์ ˆํ•œ ์ฝ˜ํ…์ธ ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๋ฉ”์ปค๋‹ˆ์ฆ˜


โ€ข ๋„ค๋น„๊ฒŒ์ด์…˜ (Navigation): ์‚ฌ์šฉ์ž๊ฐ€ ์•ฑ ๋‚ด์—์„œ ์ด๋™ํ•˜๋Š” ๊ณผ์ •


โ€ข History API: ๋ธŒ๋ผ์šฐ์ €์˜ ๋ฐฉ๋ฌธ ๊ธฐ๋ก์„ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ๋Š” JavaScript API

๐Ÿ’ก Tip: ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ๋„ SPA ๊ธฐ์ˆ ์„ ํ™œ์šฉํ•˜๋ฉด ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ํ›จ์”ฌ ์ข‹์•„์ ธ. ํŽ˜์ด์ง€ ์ „ํ™˜์ด ๋น ๋ฅด๊ณ  ๋ถ€๋“œ๋Ÿฌ์šฐ๋‹ˆ๊นŒ ์‚ฌ์šฉ์ž๋“ค์ด ๋” ์˜ค๋ž˜ ๋จธ๋ฌผ๊ฒŒ ๋˜๊ฑฐ๋“ !

๐ŸŽฏ ์™œ ๋ผ์šฐํŒ…์ด ์ค‘์š”ํ• ๊นŒ?

๋ผ์šฐํŒ…์€ SPA์˜ ์‹ฌ์žฅ์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์–ด. ๋ผ์šฐํŒ…์ด ์—†์œผ๋ฉด SPA๋Š” ๊ทธ๋ƒฅ ๋‹จ์ผ ํŽ˜์ด์ง€์ผ ๋ฟ์ด์•ผ. ํ•˜์ง€๋งŒ ๋ผ์šฐํŒ…์„ ์ถ”๊ฐ€ํ•˜๋ฉด:

๐Ÿ”— URL ๊ด€๋ฆฌ

๊ฐ ํ™”๋ฉด๋งˆ๋‹ค ๊ณ ์œ ํ•œ URL์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์–ด. ๋ถ๋งˆํฌ๋„ ๊ฐ€๋Šฅํ•˜๊ณ  ๊ณต์œ ๋„ ์‰ฌ์›Œ์ง€์ง€!

โฎ๏ธ ๋ธŒ๋ผ์šฐ์ € ํžˆ์Šคํ† ๋ฆฌ

๋’ค๋กœ ๊ฐ€๊ธฐ, ์•ž์œผ๋กœ ๊ฐ€๊ธฐ ๋ฒ„ํŠผ์ด ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•ด. ์‚ฌ์šฉ์ž๊ฐ€ ๊ธฐ๋Œ€ํ•˜๋Š” ๋Œ€๋กœ!

๐ŸŽจ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜

ํŽ˜์ด์ง€ ์ƒˆ๋กœ๊ณ ์นจ ์—†์ด ๋ถ€๋“œ๋Ÿฌ์šด ์ „ํ™˜. ์ด๊ฒŒ ๋ฐ”๋กœ ํ˜„๋Œ€์ ์ธ ์›น์˜ ๋А๋‚Œ์ด์•ผ!

์‹ค์ œ ์‚ฌ๋ก€: ๊ตฌ๊ธ€ ์ง€๋„๋ฅผ ์ƒ๊ฐํ•ด๋ด. ์ง€๋„๋ฅผ ์ด๋™ํ•˜๊ฑฐ๋‚˜ ๊ฒ€์ƒ‰ํ•  ๋•Œ๋งˆ๋‹ค URL์ด ๋ฐ”๋€Œ์ง€๋งŒ ํŽ˜์ด์ง€๋Š” ์ƒˆ๋กœ๊ณ ์นจ๋˜์ง€ ์•Š์•„. ์ด๊ฒŒ ๋ฐ”๋กœ ๋ผ์šฐํŒ…์˜ ํž˜์ด์•ผ! ๐Ÿ—บ๏ธ

๐Ÿ› ๏ธ ๋ผ์šฐํŒ…์˜ ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹

JavaScript์—์„œ ๋ผ์šฐํŒ…์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ํฌ๊ฒŒ ๋‘ ๊ฐ€์ง€์•ผ. ๊ฐ๊ฐ ์žฅ๋‹จ์ ์ด ์žˆ์œผ๋‹ˆ๊นŒ ์ƒํ™ฉ์— ๋งž๊ฒŒ ์„ ํƒํ•˜๋ฉด ๋ผ!

1๏ธโƒฃ Hash ๊ธฐ๋ฐ˜ ๋ผ์šฐํŒ… (#)

URL์— ํ•ด์‹œ(#)๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ด์•ผ. ์˜ˆ๋ฅผ ๋“ค๋ฉด example.com/#/about ์ด๋Ÿฐ ์‹์ด์ง€.

โœ… ์žฅ์ 

โ€ข ์„œ๋ฒ„ ์„ค์ •์ด ํ•„์š” ์—†์–ด (ํ•ด์‹œ ๋’ค์˜ ๋‚ด์šฉ์€ ์„œ๋ฒ„๋กœ ์ „์†ก๋˜์ง€ ์•Š์Œ)


โ€ข ๊ตฌํ˜• ๋ธŒ๋ผ์šฐ์ €์—์„œ๋„ ์ž˜ ์ž‘๋™ํ•ด


โ€ข ๊ตฌํ˜„์ด ๊ฐ„๋‹จํ•ด


โ€ข GitHub Pages ๊ฐ™์€ ์ •์  ํ˜ธ์ŠคํŒ…์—์„œ๋„ ๋ฌธ์ œ์—†์ด ์ž‘๋™



โŒ ๋‹จ์ 

โ€ข URL์ด ์ข€ ์ง€์ €๋ถ„ํ•ด ๋ณด์—ฌ (#์ด ๋“ค์–ด๊ฐ€๋‹ˆ๊นŒ)


โ€ข SEO(๊ฒ€์ƒ‰ ์—”์ง„ ์ตœ์ ํ™”)์— ๋ถˆ๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด


โ€ข ์ „๋ฌธ์ ์ด์ง€ ์•Š์•„ ๋ณด์ผ ์ˆ˜ ์žˆ์–ด

์ฝ”๋“œ ์˜ˆ์ œ๋ฅผ ๋ณผ๊นŒ?

// Hash ๊ธฐ๋ฐ˜ ๋ผ์šฐํ„ฐ ๊ธฐ๋ณธ ๊ตฌ์กฐ
class HashRouter {
  constructor(routes) {
    this.routes = routes;
    this.currentPath = '';
    
    // hashchange ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ๋“ฑ๋ก
    window.addEventListener('hashchange', () => {
      this.handleRoute();
    });
    
    // ์ดˆ๊ธฐ ๋กœ๋“œ
    this.handleRoute();
  }
  
  handleRoute() {
    // ํ˜„์žฌ ํ•ด์‹œ ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ (# ์ œ๊ฑฐ)
    this.currentPath = window.location.hash.slice(1) || '/';
    
    // ๋งค์นญ๋˜๋Š” ๋ผ์šฐํŠธ ์ฐพ๊ธฐ
    const route = this.routes[this.currentPath];
    
    if (route) {
      // ๋ผ์šฐํŠธ๊ฐ€ ์žˆ์œผ๋ฉด ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ ๋ Œ๋”๋ง
      this.render(route.component);
    } else {
      // 404 ์ฒ˜๋ฆฌ
      this.render(this.routes['/404']?.component || 'ํŽ˜์ด์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค');
    }
  }
  
  render(component) {
    const app = document.getElementById('app');
    if (typeof component === 'function') {
      app.innerHTML = component();
    } else {
      app.innerHTML = component;
    }
  }
  
  navigate(path) {
    window.location.hash = path;
  }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const routes = {
  '/': {
    component: () => '<h1>ํ™ˆ ํŽ˜์ด์ง€</h1><p>ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค! ๐Ÿ </p>'
  },
  '/about': {
    component: () => '<h1>์†Œ๊ฐœ ํŽ˜์ด์ง€</h1><p>์šฐ๋ฆฌ๋Š” ๋ฉ‹์ง„ ํŒ€์ž…๋‹ˆ๋‹ค! ๐Ÿ‘ฅ</p>'
  },
  '/contact': {
    component: () => '<h1>์—ฐ๋ฝ์ฒ˜</h1><p>์–ธ์ œ๋“  ์—ฐ๋ฝ์ฃผ์„ธ์š”! ๐Ÿ“ง</p>'
  },
  '/404': {
    component: () => '<h1>404</h1><p>ํŽ˜์ด์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์–ด์š” ๐Ÿ˜ข</p>'
  }
};

const router = new HashRouter(routes);

// ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ ๋„ค๋น„๊ฒŒ์ด์…˜
// router.navigate('/about');
๐Ÿ’ก ์‹ค์ „ ํŒ: Hash ๋ผ์šฐํŒ…์€ ํ”„๋กœํ† ํƒ€์ž…์ด๋‚˜ ๊ฐ„๋‹จํ•œ ํ”„๋กœ์ ํŠธ์— ๋”ฑ์ด์•ผ. ๋น ๋ฅด๊ฒŒ ๋งŒ๋“ค์–ด์•ผ ํ•  ๋•Œ ์ถ”์ฒœ! ๐Ÿš€

2๏ธโƒฃ History API ๊ธฐ๋ฐ˜ ๋ผ์šฐํŒ…

HTML5์—์„œ ์ œ๊ณตํ•˜๋Š” History API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ด์•ผ. URL์ด example.com/about ์ฒ˜๋Ÿผ ๊น”๋”ํ•˜๊ฒŒ ๋‚˜์™€!

โœ… ์žฅ์ 

โ€ข URL์ด ๊น”๋”ํ•˜๊ณ  ์ „๋ฌธ์ ์œผ๋กœ ๋ณด์—ฌ


โ€ข SEO์— ์œ ๋ฆฌํ•ด (๊ฒ€์ƒ‰ ์—”์ง„์ด ํฌ๋กค๋งํ•˜๊ธฐ ์ข‹์Œ)


โ€ข ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ๋” ์ž์—ฐ์Šค๋Ÿฌ์›Œ


โ€ข ํ˜„๋Œ€์ ์ธ ์›น ์•ฑ์˜ ํ‘œ์ค€



โŒ ๋‹จ์ 

โ€ข ์„œ๋ฒ„ ์„ค์ •์ด ํ•„์š”ํ•ด (๋ชจ๋“  ๊ฒฝ๋กœ๋ฅผ index.html๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ)


โ€ข ๊ตฌํ˜• ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ง€์› ์•ˆ ๋  ์ˆ˜ ์žˆ์–ด


โ€ข ๊ตฌํ˜„์ด ์กฐ๊ธˆ ๋” ๋ณต์žกํ•ด

History API ๋ผ์šฐํ„ฐ ๊ตฌํ˜„ํ•ด๋ณด์ž!

// History API ๊ธฐ๋ฐ˜ ๋ผ์šฐํ„ฐ
class HistoryRouter {
  constructor(routes) {
    this.routes = routes;
    this.currentPath = '';
    
    // popstate ์ด๋ฒคํŠธ (๋’ค๋กœ/์•ž์œผ๋กœ ๊ฐ€๊ธฐ)
    window.addEventListener('popstate', (e) => {
      this.handleRoute(window.location.pathname);
    });
    
    // ๋งํฌ ํด๋ฆญ ๊ฐ€๋กœ์ฑ„๊ธฐ
    document.addEventListener('click', (e) => {
      if (e.target.matches('[data-link]')) {
        e.preventDefault();
        this.navigate(e.target.getAttribute('href'));
      }
    });
    
    // ์ดˆ๊ธฐ ๋กœ๋“œ
    this.handleRoute(window.location.pathname);
  }
  
  handleRoute(path) {
    this.currentPath = path || '/';
    
    // ๋ผ์šฐํŠธ ๋งค์นญ (๋™์  ๋ผ์šฐํŠธ ์ง€์›)
    let matchedRoute = null;
    let params = {};
    
    for (let routePath in this.routes) {
      const match = this.matchRoute(routePath, this.currentPath);
      if (match.isMatch) {
        matchedRoute = this.routes[routePath];
        params = match.params;
        break;
      }
    }
    
    if (matchedRoute) {
      this.render(matchedRoute.component, params);
    } else {
      this.render(this.routes['/404']?.component || '404 Not Found');
    }
  }
  
  matchRoute(routePath, urlPath) {
    // ๋™์  ํŒŒ๋ผ๋ฏธํ„ฐ ์ง€์› (/user/:id ๊ฐ™์€ ํ˜•ํƒœ)
    const routeParts = routePath.split('/');
    const urlParts = urlPath.split('/');
    
    if (routeParts.length !== urlParts.length) {
      return { isMatch: false, params: {} };
    }
    
    const params = {};
    
    for (let i = 0; i < routeParts.length; i++) {
      if (routeParts[i].startsWith(':')) {
        // ๋™์  ํŒŒ๋ผ๋ฏธํ„ฐ
        const paramName = routeParts[i].slice(1);
        params[paramName] = urlParts[i];
      } else if (routeParts[i] !== urlParts[i]) {
        return { isMatch: false, params: {} };
      }
    }
    
    return { isMatch: true, params };
  }
  
  render(component, params = {}) {
    const app = document.getElementById('app');
    if (typeof component === 'function') {
      app.innerHTML = component(params);
    } else {
      app.innerHTML = component;
    }
  }
  
  navigate(path) {
    // History API๋กœ URL ๋ณ€๊ฒฝ (ํŽ˜์ด์ง€ ์ƒˆ๋กœ๊ณ ์นจ ์—†์ด)
    window.history.pushState({}, '', path);
    this.handleRoute(path);
  }
  
  back() {
    window.history.back();
  }
  
  forward() {
    window.history.forward();
  }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const routes = {
  '/': {
    component: () => `
      <h1>ํ™ˆ ํŽ˜์ด์ง€ ๐Ÿ </h1>
      <p>ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!</p>
      <a href="/about" data-link>์†Œ๊ฐœ ํŽ˜์ด์ง€๋กœ</a>
    `
  },
  '/about': {
    component: () => `
      <h1>์†Œ๊ฐœ ํŽ˜์ด์ง€ ๐Ÿ‘ฅ</h1>
      <p>์šฐ๋ฆฌ๋Š” ๋ฉ‹์ง„ ๊ฐœ๋ฐœ์ž๋“ค์ž…๋‹ˆ๋‹ค!</p>
      <a href="/" data-link>ํ™ˆ์œผ๋กœ</a>
    `
  },
  '/user/:id': {
    component: (params) => `
      <h1>์‚ฌ์šฉ์ž ํ”„๋กœํ•„ ๐Ÿ‘ค</h1>
      <p>์‚ฌ์šฉ์ž ID: ${params.id}</p>
      <a href="/" data-link>ํ™ˆ์œผ๋กœ</a>
    `
  },
  '/404': {
    component: () => `
      <h1>404 ๐Ÿ˜ข</h1>
      <p>ํŽ˜์ด์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค</p>
      <a href="/" data-link>ํ™ˆ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ</a>
    `
  }
};

const router = new HistoryRouter(routes);
โš ๏ธ ์ฃผ์˜: History API๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ์„œ๋ฒ„ ์„ค์ •์ด ํ•„์ˆ˜์•ผ! ๋ชจ๋“  ๊ฒฝ๋กœ ์š”์ฒญ์„ index.html๋กœ ๋ณด๋‚ด๋„๋ก ์„ค์ •ํ•ด์•ผ ํ•ด. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์ƒˆ๋กœ๊ณ ์นจ ์‹œ 404 ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์–ด.

โš™๏ธ ์„œ๋ฒ„ ์„ค์ • ๊ฐ€์ด๋“œ

History API๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์„œ๋ฒ„ ์„ค์ •์ด ํ•„์š”ํ•˜๋‹ค๊ณ  ํ–ˆ์ง€? ๊ฐ ์„œ๋ฒ„๋ณ„๋กœ ์–ด๋–ป๊ฒŒ ์„ค์ •ํ•˜๋Š”์ง€ ์•Œ์•„๋ณด์ž!

Apache (.htaccess)

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

Nginx

location / {
  try_files $uri $uri/ /index.html;
}

Node.js (Express)

const express = require('express');
const path = require('path');
const app = express();

// ์ •์  ํŒŒ์ผ ์ œ๊ณต
app.use(express.static(path.join(__dirname, 'public')));

// ๋ชจ๋“  ๊ฒฝ๋กœ๋ฅผ index.html๋กœ
app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'public', 'index.html'));
});

app.listen(3000, () => {
  console.log('์„œ๋ฒ„๊ฐ€ 3000๋ฒˆ ํฌํŠธ์—์„œ ์‹คํ–‰ ์ค‘! ๐Ÿš€');
});
๐Ÿ’ก ๊ฐœ๋ฐœ ํŒ: ๊ฐœ๋ฐœ ์ค‘์—๋Š” webpack-dev-server๋‚˜ Vite ๊ฐ™์€ ๋„๊ตฌ๋ฅผ ์“ฐ๋ฉด ์ž๋™์œผ๋กœ ์„ค์ •ํ•ด์ค˜์„œ ํŽธํ•ด! ๐Ÿ˜Ž

๐ŸŽจ ์‹ค์ „ ๋ผ์šฐํ„ฐ ๊ตฌํ˜„ํ•˜๊ธฐ

์ด์ œ ์ง„์งœ ์‹ค๋ฌด์—์„œ ์“ธ ์ˆ˜ ์žˆ๋Š” ๋ผ์šฐํ„ฐ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž! ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด๋ณผ๊ฒŒ.

๊ณ ๊ธ‰ ๊ธฐ๋Šฅ์ด ํฌํ•จ๋œ ๋ผ์šฐํ„ฐ

class AdvancedRouter {
  constructor(routes, options = {}) {
    this.routes = routes;
    this.currentPath = '';
    this.params = {};
    this.query = {};
    this.beforeEachHooks = [];
    this.afterEachHooks = [];
    this.mode = options.mode || 'history'; // 'history' or 'hash'
    
    this.init();
  }
  
  init() {
    if (this.mode === 'history') {
      window.addEventListener('popstate', () => {
        this.handleRoute(window.location.pathname);
      });
      
      document.addEventListener('click', (e) => {
        if (e.target.matches('[data-link]')) {
          e.preventDefault();
          this.navigate(e.target.getAttribute('href'));
        }
      });
    } else {
      window.addEventListener('hashchange', () => {
        this.handleRoute(window.location.hash.slice(1));
      });
    }
    
    const initialPath = this.mode === 'history' 
      ? window.location.pathname 
      : window.location.hash.slice(1) || '/';
    
    this.handleRoute(initialPath);
  }
  
  // ๋„ค๋น„๊ฒŒ์ด์…˜ ๊ฐ€๋“œ (๋ผ์šฐํŠธ ์ด๋™ ์ „ ์‹คํ–‰)
  beforeEach(hook) {
    this.beforeEachHooks.push(hook);
  }
  
  // ๋„ค๋น„๊ฒŒ์ด์…˜ ํ›„ ์‹คํ–‰
  afterEach(hook) {
    this.afterEachHooks.push(hook);
  }
  
  async handleRoute(path) {
    const from = this.currentPath;
    const to = path || '/';
    
    // ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ ํŒŒ์‹ฑ
    const [pathname, queryString] = to.split('?');
    this.query = this.parseQuery(queryString);
    
    // beforeEach ํ›… ์‹คํ–‰
    for (let hook of this.beforeEachHooks) {
      const result = await hook(to, from);
      if (result === false) {
        // ๋„ค๋น„๊ฒŒ์ด์…˜ ์ทจ์†Œ
        return;
      }
      if (typeof result === 'string') {
        // ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ
        this.navigate(result);
        return;
      }
    }
    
    // ๋ผ์šฐํŠธ ๋งค์นญ
    let matchedRoute = null;
    let params = {};
    
    for (let routePath in this.routes) {
      const match = this.matchRoute(routePath, pathname);
      if (match.isMatch) {
        matchedRoute = this.routes[routePath];
        params = match.params;
        break;
      }
    }
    
    if (matchedRoute) {
      this.currentPath = to;
      this.params = params;
      
      // ๋ฉ”ํƒ€ ์ •๋ณด ์ฒ˜๋ฆฌ (ํŽ˜์ด์ง€ ํƒ€์ดํ‹€ ๋“ฑ)
      if (matchedRoute.meta) {
        this.handleMeta(matchedRoute.meta);
      }
      
      await this.render(matchedRoute.component, params, this.query);
      
      // afterEach ํ›… ์‹คํ–‰
      for (let hook of this.afterEachHooks) {
        await hook(to, from);
      }
    } else {
      this.render(this.routes['/404']?.component || '404 Not Found');
    }
  }
  
  matchRoute(routePath, urlPath) {
    const routeParts = routePath.split('/').filter(p => p);
    const urlParts = urlPath.split('/').filter(p => p);
    
    if (routeParts.length !== urlParts.length) {
      return { isMatch: false, params: {} };
    }
    
    const params = {};
    
    for (let i = 0; i < routeParts.length; i++) {
      if (routeParts[i].startsWith(':')) {
        const paramName = routeParts[i].slice(1);
        params[paramName] = decodeURIComponent(urlParts[i]);
      } else if (routeParts[i] !== urlParts[i]) {
        return { isMatch: false, params: {} };
      }
    }
    
    return { isMatch: true, params };
  }
  
  parseQuery(queryString) {
    if (!queryString) return {};
    
    const query = {};
    const pairs = queryString.split('&');
    
    for (let pair of pairs) {
      const [key, value] = pair.split('=');
      query[decodeURIComponent(key)] = decodeURIComponent(value || '');
    }
    
    return query;
  }
  
  handleMeta(meta) {
    if (meta.title) {
      document.title = meta.title;
    }
    
    if (meta.description) {
      let metaDesc = document.querySelector('meta[name="description"]');
      if (!metaDesc) {
        metaDesc = document.createElement('meta');
        metaDesc.name = 'description';
        document.head.appendChild(metaDesc);
      }
      metaDesc.content = meta.description;
    }
  }
  
  async render(component, params = {}, query = {}) {
    const app = document.getElementById('app');
    
    if (typeof component === 'function') {
      const result = component({ params, query, router: this });
      
      // Promise ์ง€์› (๋น„๋™๊ธฐ ์ปดํฌ๋„ŒํŠธ)
      if (result instanceof Promise) {
        app.innerHTML = '<div class="loading">๋กœ๋”ฉ ์ค‘... โณ</div>';
        app.innerHTML = await result;
      } else {
        app.innerHTML = result;
      }
    } else {
      app.innerHTML = component;
    }
  }
  
  navigate(path, replace = false) {
    if (this.mode === 'history') {
      if (replace) {
        window.history.replaceState({}, '', path);
      } else {
        window.history.pushState({}, '', path);
      }
      this.handleRoute(path);
    } else {
      window.location.hash = path;
    }
  }
  
  back() {
    window.history.back();
  }
  
  forward() {
    window.history.forward();
  }
  
  // ํ˜„์žฌ ๋ผ์šฐํŠธ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
  getCurrentRoute() {
    return {
      path: this.currentPath,
      params: this.params,
      query: this.query
    };
  }
}

// ์‹ค์ „ ์‚ฌ์šฉ ์˜ˆ์ œ
const routes = {
  '/': {
    component: () => `
      <div class="page">
        <h1>ํ™ˆ ํŽ˜์ด์ง€ ๐Ÿ </h1>
        <p>์žฌ๋Šฅ๋„ท์—์„œ ๋‹ค์–‘ํ•œ ๊ฐœ๋ฐœ ์žฌ๋Šฅ์„ ๊ณต์œ ํ•ด๋ณด์„ธ์š”!</p>
        <nav>
          <a href="/about" data-link>์†Œ๊ฐœ</a> |
          <a href="/user/123" data-link>์‚ฌ์šฉ์ž ํ”„๋กœํ•„</a> |
          <a href="/search?q=javascript&sort=latest" data-link>๊ฒ€์ƒ‰</a>
        </nav>
      </div>
    `,
    meta: {
      title: 'ํ™ˆ - ๋‚ด ๋ฉ‹์ง„ SPA',
      description: 'SPA ๋ผ์šฐํŒ… ์˜ˆ์ œ ํ™ˆํŽ˜์ด์ง€'
    }
  },
  
  '/about': {
    component: () => `
      <div class="page">
        <h1>์†Œ๊ฐœ ํŽ˜์ด์ง€ ๐Ÿ‘ฅ</h1>
        <p>์šฐ๋ฆฌ๋Š” JavaScript๋ฅผ ์‚ฌ๋ž‘ํ•˜๋Š” ๊ฐœ๋ฐœ์ž๋“ค์ž…๋‹ˆ๋‹ค!</p>
        <a href="/" data-link>โ† ํ™ˆ์œผ๋กœ</a>
      </div>
    `,
    meta: {
      title: '์†Œ๊ฐœ - ๋‚ด ๋ฉ‹์ง„ SPA'
    }
  },
  
  '/user/:id': {
    component: ({ params }) => `
      <div class="page">
        <h1>์‚ฌ์šฉ์ž ํ”„๋กœํ•„ ๐Ÿ‘ค</h1>
        <p>์‚ฌ์šฉ์ž ID: <strong>${params.id}</strong></p>
        <a href="/" data-link>โ† ํ™ˆ์œผ๋กœ</a>
      </div>
    `,
    meta: {
      title: '์‚ฌ์šฉ์ž ํ”„๋กœํ•„'
    }
  },
  
  '/search': {
    component: ({ query }) => `
      <div class="page">
        <h1>๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ๐Ÿ”</h1>
        <p>๊ฒ€์ƒ‰์–ด: <strong>${query.q || '์—†์Œ'}</strong></p>
        <p>์ •๋ ฌ: <strong>${query.sort || '๊ธฐ๋ณธ'}</strong></p>
        <a href="/" data-link>โ† ํ™ˆ์œผ๋กœ</a>
      </div>
    `
  },
  
  '/protected': {
    component: () => `
      <div class="page">
        <h1>๋ณดํ˜ธ๋œ ํŽ˜์ด์ง€ ๐Ÿ”’</h1>
        <p>์ธ์ฆ๋œ ์‚ฌ์šฉ์ž๋งŒ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!</p>
      </div>
    `
  },
  
  '/404': {
    component: () => `
      <div class="page">
        <h1>404 ๐Ÿ˜ข</h1>
        <p>ํŽ˜์ด์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค</p>
        <a href="/" data-link>ํ™ˆ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ</a>
      </div>
    `
  }
};

const router = new AdvancedRouter(routes, { mode: 'history' });

// ๋„ค๋น„๊ฒŒ์ด์…˜ ๊ฐ€๋“œ ์˜ˆ์ œ (์ธ์ฆ ์ฒดํฌ)
router.beforeEach((to, from) => {
  console.log(`${from} โ†’ ${to} ์ด๋™ ์ค‘...`);
  
  // ๋ณดํ˜ธ๋œ ํŽ˜์ด์ง€ ์ ‘๊ทผ ์‹œ ์ธ์ฆ ์ฒดํฌ
  if (to === '/protected') {
    const isAuthenticated = false; // ์‹ค์ œ๋กœ๋Š” ์ธ์ฆ ์ƒํƒœ ์ฒดํฌ
    
    if (!isAuthenticated) {
      alert('๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค!');
      return '/'; // ํ™ˆ์œผ๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ
    }
  }
  
  // ๊ณ„์† ์ง„ํ–‰
  return true;
});

// ํŽ˜์ด์ง€ ์ด๋™ ํ›„ ์Šคํฌ๋กค ๋งจ ์œ„๋กœ
router.afterEach(() => {
  window.scrollTo(0, 0);
});

๐ŸŽ‰ ์™€! ์ด์ œ ์ง„์งœ ์‹ค๋ฌด๊ธ‰ ๋ผ์šฐํ„ฐ๊ฐ€ ์™„์„ฑ๋์–ด! ์ด ๋ผ์šฐํ„ฐ๋Š”:


โ€ข ๋™์  ๋ผ์šฐํŠธ ํŒŒ๋ผ๋ฏธํ„ฐ ์ง€์› (/user/:id)

โ€ข ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ ํŒŒ์‹ฑ (?q=search&sort=latest)

โ€ข ๋„ค๋น„๊ฒŒ์ด์…˜ ๊ฐ€๋“œ (beforeEach, afterEach)

โ€ข ๋ฉ”ํƒ€ ์ •๋ณด ๊ด€๋ฆฌ (ํŽ˜์ด์ง€ ํƒ€์ดํ‹€, ์„ค๋ช…)

โ€ข ๋น„๋™๊ธฐ ์ปดํฌ๋„ŒํŠธ ์ง€์›

โ€ข History API์™€ Hash ๋ชจ๋“œ ๋ชจ๋‘ ์ง€์›


์ด ์ •๋„๋ฉด ์ค‘์†Œ๊ทœ๋ชจ ํ”„๋กœ์ ํŠธ์—์„œ ์ถฉ๋ถ„ํžˆ ์“ธ ์ˆ˜ ์žˆ์–ด! ๐Ÿ’ช

๐Ÿš€ ์ธ๊ธฐ ๋ผ์šฐํŒ… ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค

๋ฌผ๋ก  ์ง์ ‘ ๋งŒ๋“ค์–ด ์“ฐ๋Š” ๊ฒƒ๋„ ์ข‹์ง€๋งŒ, ์‹ค๋ฌด์—์„œ๋Š” ๊ฒ€์ฆ๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์“ฐ๋Š” ๊ฒŒ ๋” ์•ˆ์ „ํ•˜๊ณ  ํšจ์œจ์ ์ด์•ผ. ๋Œ€ํ‘œ์ ์ธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์„ ์†Œ๊ฐœํ• ๊ฒŒ!

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ”„๋ ˆ์ž„์›Œํฌ ํŠน์ง• ์ธ๊ธฐ๋„
React Router React ๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๋Š” React ๋ผ์šฐํŒ… ์†”๋ฃจ์…˜ โญโญโญโญโญ
Vue Router Vue.js Vue ๊ณต์‹ ๋ผ์šฐํ„ฐ, ์ง๊ด€์ ์ธ API โญโญโญโญโญ
Angular Router Angular Angular ๋‚ด์žฅ ๋ผ์šฐํ„ฐ, ๊ฐ•๋ ฅํ•œ ๊ธฐ๋Šฅ โญโญโญโญ
Page.js Vanilla JS ๊ฐ€๋ณ๊ณ  ๊ฐ„๋‹จํ•œ ํด๋ผ์ด์–ธํŠธ ๋ผ์šฐํ„ฐ โญโญโญ
Navigo Vanilla JS ์˜์กด์„ฑ ์—†๋Š” ์ˆœ์ˆ˜ JS ๋ผ์šฐํ„ฐ โญโญโญ

React Router ์˜ˆ์ œ

React๋ฅผ ์“ด๋‹ค๋ฉด React Router๊ฐ€ ์‚ฌ์‹ค์ƒ ํ‘œ์ค€์ด์•ผ. ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ๋ณด์ž!

import { BrowserRouter, Routes, Route, Link, useParams } from 'react-router-dom';

// ์ปดํฌ๋„ŒํŠธ๋“ค
function Home() {
  return (
    <div>
      <h1>ํ™ˆ ํŽ˜์ด์ง€ ๐Ÿ </h1>
      <nav>
        <Link to="/about">์†Œ๊ฐœ</Link> |
        <Link to="/user/123">์‚ฌ์šฉ์ž ํ”„๋กœํ•„</Link>
      </nav>
    </div>
  );
}

function About() {
  return <h1>์†Œ๊ฐœ ํŽ˜์ด์ง€ ๐Ÿ‘ฅ</h1>;
}

function UserProfile() {
  const { id } = useParams();
  return (
    <div>
      <h1>์‚ฌ์šฉ์ž ํ”„๋กœํ•„ ๐Ÿ‘ค</h1>
      <p>์‚ฌ์šฉ์ž ID: {id}</p>
    </div>
  );
}

function NotFound() {
  return <h1>404 - ํŽ˜์ด์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค ๐Ÿ˜ข</h1>;
}

// ์•ฑ ์ปดํฌ๋„ŒํŠธ
function App() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
        <Route path="/user/:id" element={<UserProfile />} />
        <Route path="*" element={<NotFound />} />
      </Routes>
    </BrowserRouter>
  );
}

export default App;

Vue Router ์˜ˆ์ œ

Vue.js๋ฅผ ์“ด๋‹ค๋ฉด Vue Router! ์ด๊ฒƒ๋„ ์ •๋ง ์ง๊ด€์ ์ด์•ผ.

import { createRouter, createWebHistory } from 'vue-router';
import Home from './components/Home.vue';
import About from './components/About.vue';
import UserProfile from './components/UserProfile.vue';

// ๋ผ์šฐํŠธ ์ •์˜
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: { title: 'ํ™ˆ ํŽ˜์ด์ง€' }
  },
  {
    path: '/about',
    name: 'About',
    component: About,
    meta: { title: '์†Œ๊ฐœ' }
  },
  {
    path: '/user/:id',
    name: 'UserProfile',
    component: UserProfile,
    meta: { title: '์‚ฌ์šฉ์ž ํ”„๋กœํ•„' }
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('./components/NotFound.vue')
  }
];

// ๋ผ์šฐํ„ฐ ์ƒ์„ฑ
const router = createRouter({
  history: createWebHistory(),
  routes
});

// ๋„ค๋น„๊ฒŒ์ด์…˜ ๊ฐ€๋“œ
router.beforeEach((to, from, next) => {
  // ํŽ˜์ด์ง€ ํƒ€์ดํ‹€ ์„ค์ •
  document.title = to.meta.title || '๋‚ด ์•ฑ';
  
  // ์ธ์ฆ ์ฒดํฌ ์˜ˆ์ œ
  if (to.meta.requiresAuth && !isAuthenticated()) {
    next('/login');
  } else {
    next();
  }
});

export default router;
๐Ÿ’ก ์„ ํƒ ๊ฐ€์ด๋“œ: ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์“ด๋‹ค๋ฉด ํ•ด๋‹น ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๊ณต์‹ ๋ผ์šฐํ„ฐ๋ฅผ ์“ฐ๋Š” ๊ฒŒ ๋ฒ ์ŠคํŠธ์•ผ. Vanilla JS ํ”„๋กœ์ ํŠธ๋ผ๋ฉด ์ง์ ‘ ๋งŒ๋“ค๊ฑฐ๋‚˜ Page.js, Navigo ๊ฐ™์€ ๊ฐ€๋ฒผ์šด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”์ฒœํ•ด!

๐ŸŽฏ ๋„ค๋น„๊ฒŒ์ด์…˜ ํŒจํ„ด๊ณผ UX

๋ผ์šฐํŒ…๋งŒ ์ž˜ ๊ตฌํ˜„ํ•œ๋‹ค๊ณ  ๋์ด ์•„๋‹ˆ์•ผ. ์‚ฌ์šฉ์ž ๊ฒฝํ—˜(UX)์„ ๊ณ ๋ คํ•œ ๋„ค๋น„๊ฒŒ์ด์…˜ ํŒจํ„ด๋„ ์ค‘์š”ํ•ด!

1. ๋กœ๋”ฉ ์ƒํƒœ ํ‘œ์‹œ

ํŽ˜์ด์ง€ ์ „ํ™˜ ์‹œ ๋กœ๋”ฉ ์ธ๋””์ผ€์ดํ„ฐ๋ฅผ ๋ณด์—ฌ์ฃผ๋ฉด ์‚ฌ์šฉ์ž๊ฐ€ ๋ญ”๊ฐ€ ์ง„ํ–‰๋˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฑธ ์•Œ ์ˆ˜ ์žˆ์–ด.

class RouterWithLoading extends AdvancedRouter {
  async render(component, params = {}, query = {}) {
    const app = document.getElementById('app');
    
    // ๋กœ๋”ฉ ํ‘œ์‹œ
    this.showLoading();
    
    try {
      if (typeof component === 'function') {
        const result = component({ params, query, router: this });
        
        if (result instanceof Promise) {
          const html = await result;
          app.innerHTML = html;
        } else {
          app.innerHTML = result;
        }
      } else {
        app.innerHTML = component;
      }
    } catch (error) {
      console.error('๋ Œ๋”๋ง ์—๋Ÿฌ:', error);
      app.innerHTML = '<h1>์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค ๐Ÿ˜ข</h1>';
    } finally {
      // ๋กœ๋”ฉ ์ˆจ๊ธฐ๊ธฐ
      this.hideLoading();
    }
  }
  
  showLoading() {
    let loader = document.getElementById('page-loader');
    if (!loader) {
      loader = document.createElement('div');
      loader.id = 'page-loader';
      loader.innerHTML = `
        <div style="
          position: fixed;
          top: 0;
          left: 0;
          right: 0;
          height: 3px;
          background: linear-gradient(90deg, #667eea, #764ba2);
          animation: loading 1s ease-in-out infinite;
          z-index: 9999;
        "></div>
        <style>
          @keyframes loading {
            0% { transform: translateX(-100%); }
            100% { transform: translateX(100%); }
          }
        </style>
      `;
      document.body.appendChild(loader);
    }
    loader.style.display = 'block';
  }
  
  hideLoading() {
    const loader = document.getElementById('page-loader');
    if (loader) {
      loader.style.display = 'none';
    }
  }
}

2. ํŽ˜์ด์ง€ ์ „ํ™˜ ์• ๋‹ˆ๋ฉ”์ด์…˜

๋ถ€๋“œ๋Ÿฌ์šด ์ „ํ™˜ ํšจ๊ณผ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ํ›จ์”ฌ ์„ธ๋ จ๋˜๊ฒŒ ๋ณด์—ฌ!

// CSS ์ „ํ™˜ ํšจ๊ณผ
const styles = `
  .page-transition {
    animation: fadeIn 0.3s ease-in-out;
  }
  
  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  .page-transition-out {
    animation: fadeOut 0.2s ease-in-out;
  }
  
  @keyframes fadeOut {
    from {
      opacity: 1;
      transform: translateY(0);
    }
    to {
      opacity: 0;
      transform: translateY(-20px);
    }
  }
`;

// ์Šคํƒ€์ผ ์ถ”๊ฐ€
const styleSheet = document.createElement('style');
styleSheet.textContent = styles;
document.head.appendChild(styleSheet);

// ๋ผ์šฐํ„ฐ์— ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ถ”๊ฐ€
class AnimatedRouter extends RouterWithLoading {
  async render(component, params = {}, query = {}) {
    const app = document.getElementById('app');
    
    // ํŽ˜์ด๋“œ ์•„์›ƒ
    app.classList.add('page-transition-out');
    await new Promise(resolve => setTimeout(resolve, 200));
    
    // ์ฝ˜ํ…์ธ  ๋ณ€๊ฒฝ
    await super.render(component, params, query);
    
    // ํŽ˜์ด๋“œ ์ธ
    app.classList.remove('page-transition-out');
    app.classList.add('page-transition');
    
    setTimeout(() => {
      app.classList.remove('page-transition');
    }, 300);
  }
}

3. ๋ธŒ๋ ˆ๋“œํฌ๋Ÿผ(Breadcrumb) ๋„ค๋น„๊ฒŒ์ด์…˜

์‚ฌ์šฉ์ž๊ฐ€ ํ˜„์žฌ ์–ด๋””์— ์žˆ๋Š”์ง€ ์•Œ๋ ค์ฃผ๋Š” ๋ธŒ๋ ˆ๋“œํฌ๋Ÿผ๋„ ์ค‘์š”ํ•ด!

function generateBreadcrumb(path) {
  const parts = path.split('/').filter(p => p);
  let breadcrumb = '<nav class="breadcrumb">';
  breadcrumb += '<a href="/" data-link>๐Ÿ  ํ™ˆ</a>';
  
  let currentPath = '';
  for (let i = 0; i < parts.length; i++) {
    currentPath += '/' + parts[i];
    const isLast = i === parts.length - 1;
    
    if (isLast) {
      breadcrumb += ` > <span>${parts[i]}</span>`;
    } else {
      breadcrumb += ` > <a href="${currentPath}" data-link>${parts[i]}</a>`;
    }
  }
  
  breadcrumb += '</nav>';
  return breadcrumb;
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const routes = {
  '/products/category/electronics': {
    component: ({ params }) => `
      ${generateBreadcrumb('/products/category/electronics')}
      <h1>์ „์ž์ œํ’ˆ ์นดํ…Œ๊ณ ๋ฆฌ ๐Ÿ“ฑ</h1>
      <p>๋‹ค์–‘ํ•œ ์ „์ž์ œํ’ˆ์„ ๋งŒ๋‚˜๋ณด์„ธ์š”!</p>
    `
  }
};

4. ์Šคํฌ๋กค ๋ณต์›

๋’ค๋กœ ๊ฐ€๊ธฐ ํ–ˆ์„ ๋•Œ ์ด์ „ ์Šคํฌ๋กค ์œ„์น˜๋กœ ๋Œ์•„๊ฐ€๋ฉด ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ์ข‹์•„์ ธ!

class ScrollRestorationRouter extends AnimatedRouter {
  constructor(routes, options = {}) {
    super(routes, options);
    this.scrollPositions = new Map();
  }
  
  async handleRoute(path) {
    // ํ˜„์žฌ ์Šคํฌ๋กค ์œ„์น˜ ์ €์žฅ
    if (this.currentPath) {
      this.scrollPositions.set(this.currentPath, window.scrollY);
    }
    
    await super.handleRoute(path);
    
    // ์Šคํฌ๋กค ์œ„์น˜ ๋ณต์› (๋’ค๋กœ ๊ฐ€๊ธฐ์ธ ๊ฒฝ์šฐ)
    if (this.scrollPositions.has(path)) {
      setTimeout(() => {
        window.scrollTo(0, this.scrollPositions.get(path));
      }, 100);
    } else {
      // ์ƒˆ ํŽ˜์ด์ง€๋Š” ๋งจ ์œ„๋กœ
      window.scrollTo(0, 0);
    }
  }
}

๐ŸŽจ UX ์ฒดํฌ๋ฆฌ์ŠคํŠธ


โœ… ๋กœ๋”ฉ ์ƒํƒœ ํ‘œ์‹œ

โœ… ๋ถ€๋“œ๋Ÿฌ์šด ํŽ˜์ด์ง€ ์ „ํ™˜

โœ… ๋ช…ํ™•ํ•œ ๋„ค๋น„๊ฒŒ์ด์…˜ (๋ธŒ๋ ˆ๋“œํฌ๋Ÿผ, ๋ฉ”๋‰ด ํ•˜์ด๋ผ์ดํŠธ)

โœ… ์Šคํฌ๋กค ์œ„์น˜ ๊ด€๋ฆฌ

โœ… ์—๋Ÿฌ ์ฒ˜๋ฆฌ (404, ๋„คํŠธ์›Œํฌ ์˜ค๋ฅ˜)

โœ… ์ ‘๊ทผ์„ฑ (ํ‚ค๋ณด๋“œ ๋„ค๋น„๊ฒŒ์ด์…˜, ์Šคํฌ๋ฆฐ ๋ฆฌ๋”)

โœ… ๋ชจ๋ฐ”์ผ ์ตœ์ ํ™”

๐Ÿ”’ ๋ณด์•ˆ๊ณผ ์ธ์ฆ

SPA์—์„œ ๋ผ์šฐํŒ…์„ ๊ตฌํ˜„ํ•  ๋•Œ ๋ณด์•ˆ๋„ ์‹ ๊ฒฝ ์จ์•ผ ํ•ด! ํŠนํžˆ ์ธ์ฆ์ด ํ•„์š”ํ•œ ํŽ˜์ด์ง€ ์ฒ˜๋ฆฌ๊ฐ€ ์ค‘์š”ํ•˜์ง€.

์ธ์ฆ ๊ฐ€๋“œ ๊ตฌํ˜„

// ๊ฐ„๋‹จํ•œ ์ธ์ฆ ๊ด€๋ฆฌ์ž
class AuthManager {
  constructor() {
    this.token = localStorage.getItem('authToken');
    this.user = null;
  }
  
  isAuthenticated() {
    return !!this.token;
  }
  
  async login(username, password) {
    try {
      // ์‹ค์ œ๋กœ๋Š” API ํ˜ธ์ถœ
      const response = await fetch('/api/login', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ username, password })
      });
      
      const data = await response.json();
      
      if (data.token) {
        this.token = data.token;
        this.user = data.user;
        localStorage.setItem('authToken', data.token);
        return true;
      }
      
      return false;
    } catch (error) {
      console.error('๋กœ๊ทธ์ธ ์—๋Ÿฌ:', error);
      return false;
    }
  }
  
  logout() {
    this.token = null;
    this.user = null;
    localStorage.removeItem('authToken');
  }
  
  getUser() {
    return this.user;
  }
}

const auth = new AuthManager();

// ๋ผ์šฐํ„ฐ์— ์ธ์ฆ ๊ฐ€๋“œ ์ถ”๊ฐ€
const protectedRoutes = {
  '/': {
    component: () => `
      <h1>ํ™ˆ ํŽ˜์ด์ง€ ๐Ÿ </h1>
      <a href="/dashboard" data-link>๋Œ€์‹œ๋ณด๋“œ (๋กœ๊ทธ์ธ ํ•„์š”)</a>
    `
  },
  
  '/login': {
    component: () => `
      <div class="login-page">
        <h1>๋กœ๊ทธ์ธ ๐Ÿ”</h1>
        <form id="loginForm">
          <input type="text" id="username" placeholder="์‚ฌ์šฉ์ž๋ช…" required>
          <input type="password" id="password" placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" required>
          <button type="submit">๋กœ๊ทธ์ธ</button>
        </form>
      </div>
      <script>
        document.getElementById('loginForm').addEventListener('submit', async (e) => {
          e.preventDefault();
          const username = document.getElementById('username').value;
          const password = document.getElementById('password').value;
          
          const success = await auth.login(username, password);
          if (success) {
            router.navigate('/dashboard');
          } else {
            alert('๋กœ๊ทธ์ธ ์‹คํŒจ!');
          }
        });
      </script>
    `
  },
  
  '/dashboard': {
    component: () => {
      const user = auth.getUser();
      return `
        <div class="dashboard">
          <h1>๋Œ€์‹œ๋ณด๋“œ ๐Ÿ“Š</h1>
          <p>ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค, ${user?.name || '์‚ฌ์šฉ์ž'}๋‹˜!</p>
          <button onclick="auth.logout(); router.navigate('/');">
            ๋กœ๊ทธ์•„์›ƒ
          </button>
        </div>
      `;
    },
    meta: {
      requiresAuth: true
    }
  },
  
  '/admin': {
    component: () => `
      <div class="admin-page">
        <h1>๊ด€๋ฆฌ์ž ํŽ˜์ด์ง€ ๐Ÿ‘‘</h1>
        <p>๊ด€๋ฆฌ์ž ์ „์šฉ ํŽ˜์ด์ง€์ž…๋‹ˆ๋‹ค.</p>
      </div>
    `,
    meta: {
      requiresAuth: true,
      requiresAdmin: true
    }
  }
};

const router = new AdvancedRouter(protectedRoutes);

// ์ธ์ฆ ๊ฐ€๋“œ
router.beforeEach((to, from) => {
  const route = protectedRoutes[to];
  
  if (route?.meta?.requiresAuth) {
    if (!auth.isAuthenticated()) {
      alert('๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค!');
      return '/login';
    }
    
    if (route.meta.requiresAdmin) {
      const user = auth.getUser();
      if (!user?.isAdmin) {
        alert('๊ด€๋ฆฌ์ž ๊ถŒํ•œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค!');
        return '/';
      }
    }
  }
  
  return true;
});
โš ๏ธ ์ค‘์š”ํ•œ ๋ณด์•ˆ ํŒ:
1. ํด๋ผ์ด์–ธํŠธ ์ธก ์ธ์ฆ๋งŒ์œผ๋กœ๋Š” ๋ถ€์กฑํ•ด! ์„œ๋ฒ„์—์„œ๋„ ๋ฐ˜๋“œ์‹œ ๊ถŒํ•œ์„ ์ฒดํฌํ•ด์•ผ ํ•ด.
2. ๋ฏผ๊ฐํ•œ ๋ฐ์ดํ„ฐ๋Š” ํด๋ผ์ด์–ธํŠธ์— ์ €์žฅํ•˜์ง€ ๋งˆ! ํ† ํฐ๋งŒ ์ €์žฅํ•˜๊ณ  ํ•„์š”ํ•  ๋•Œ ์„œ๋ฒ„์—์„œ ๊ฐ€์ ธ์™€.
3. HTTPS๋ฅผ ์‚ฌ์šฉํ•ด! ํ† ํฐ์ด ์ค‘๊ฐ„์— ํƒˆ์ทจ๋˜๋ฉด ํฐ์ผ๋‚˜.
4. ํ† ํฐ ๋งŒ๋ฃŒ๋ฅผ ๊ตฌํ˜„ํ•ด! ์˜๊ตฌ์ ์ธ ํ† ํฐ์€ ์œ„ํ—˜ํ•ด.

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™”

SPA๋Š” ์ดˆ๊ธฐ ๋กœ๋”ฉ์ด ๋А๋ฆด ์ˆ˜ ์žˆ์–ด. ํ•˜์ง€๋งŒ ๋ช‡ ๊ฐ€์ง€ ๊ธฐ๋ฒ•์œผ๋กœ ์—„์ฒญ๋‚˜๊ฒŒ ๋น ๋ฅด๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด!

1. ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ… (Code Splitting)

๋ชจ๋“  ์ฝ”๋“œ๋ฅผ ํ•œ ๋ฒˆ์— ๋กœ๋“œํ•˜์ง€ ๋ง๊ณ , ํ•„์š”ํ•  ๋•Œ๋งŒ ๋กœ๋“œํ•˜์ž!

// ๋™์  import๋ฅผ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ…
const routes = {
  '/': {
    component: () => import('./pages/Home.js').then(m => m.default())
  },
  
  '/about': {
    component: async () => {
      const module = await import('./pages/About.js');
      return module.default();
    }
  },
  
  '/heavy-page': {
    // ๋ฌด๊ฑฐ์šด ํŽ˜์ด์ง€๋Š” ํ•„์š”ํ•  ๋•Œ๋งŒ ๋กœ๋“œ
    component: async () => {
      const [pageModule, chartModule] = await Promise.all([
        import('./pages/HeavyPage.js'),
        import('./lib/charts.js')
      ]);
      
      return pageModule.default(chartModule);
    }
  }
};

// Webpack์ด๋‚˜ Vite ๊ฐ™์€ ๋ฒˆ๋“ค๋Ÿฌ๊ฐ€ ์ž๋™์œผ๋กœ ์ฒญํฌ๋ฅผ ๋ถ„๋ฆฌํ•ด์ค˜!

2. ํ”„๋ฆฌํŽ˜์นญ (Prefetching)

์‚ฌ์šฉ์ž๊ฐ€ ํด๋ฆญํ•˜๊ธฐ ์ „์— ๋ฏธ๋ฆฌ ๋กœ๋“œํ•ด๋‘๋ฉด ๋” ๋น ๋ฅด๊ฒŒ ๋А๊ปด์ ธ!

class PrefetchRouter extends AdvancedRouter {
  constructor(routes, options = {}) {
    super(routes, options);
    this.prefetchedRoutes = new Set();
    this.setupPrefetch();
  }
  
  setupPrefetch() {
    // ๋งํฌ์— ๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ฆฌ๋ฉด ํ”„๋ฆฌํŽ˜์น˜
    document.addEventListener('mouseover', (e) => {
      if (e.target.matches('[data-link]')) {
        const href = e.target.getAttribute('href');
        this.prefetch(href);
      }
    });
    
    // Intersection Observer๋กœ ๋ทฐํฌํŠธ์— ๋“ค์–ด์˜ค๋ฉด ํ”„๋ฆฌํŽ˜์น˜
    const observer = new IntersectionObserver((entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          const href = entry.target.getAttribute('href');
          this.prefetch(href);
        }
      });
    });
    
    // data-prefetch ์†์„ฑ์ด ์žˆ๋Š” ๋งํฌ ๊ด€์ฐฐ
    document.querySelectorAll('[data-prefetch]').forEach(link => {
      observer.observe(link);
    });
  }
  
  async prefetch(path) {
    if (this.prefetchedRoutes.has(path)) {
      return; // ์ด๋ฏธ ํ”„๋ฆฌํŽ˜์น˜๋จ
    }
    
    const route = this.routes[path];
    if (route && typeof route.component === 'function') {
      try {
        // ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฏธ๋ฆฌ ๋กœ๋“œ (๋ Œ๋”๋ง์€ ํ•˜์ง€ ์•Š์Œ)
        const component = route.component;
        if (component.constructor.name === 'AsyncFunction') {
          await component({ params: {}, query: {} });
        }
        
        this.prefetchedRoutes.add(path);
        console.log(`โœ… ${path} ํ”„๋ฆฌํŽ˜์น˜ ์™„๋ฃŒ`);
      } catch (error) {
        console.error(`ํ”„๋ฆฌํŽ˜์น˜ ์‹คํŒจ: ${path}`, error);
      }
    }
  }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const routes = {
  '/': {
    component: () => `
      <h1>ํ™ˆ ํŽ˜์ด์ง€</h1>
      <!-- ๋งˆ์šฐ์Šค ์˜ค๋ฒ„ ์‹œ ํ”„๋ฆฌํŽ˜์น˜ -->
      <a href="/about" data-link>์†Œ๊ฐœ</a>
      
      <!-- ๋ทฐํฌํŠธ์— ๋“ค์–ด์˜ค๋ฉด ํ”„๋ฆฌํŽ˜์น˜ -->
      <a href="/products" data-link data-prefetch>์ œํ’ˆ ๋ชฉ๋ก</a>
    `
  }
};

3. ์บ์‹ฑ ์ „๋žต

ํ•œ ๋ฒˆ ๋กœ๋“œํ•œ ๋ฐ์ดํ„ฐ๋Š” ์บ์‹œ์— ์ €์žฅํ•ด์„œ ์žฌ์‚ฌ์šฉํ•˜์ž!

class CachedRouter extends PrefetchRouter {
  constructor(routes, options = {}) {
    super(routes, options);
    this.cache = new Map();
    this.cacheTimeout = options.cacheTimeout || 5 * 60 * 1000; // 5๋ถ„
  }
  
  async fetchData(url, options = {}) {
    const cacheKey = url + JSON.stringify(options);
    
    // ์บ์‹œ ํ™•์ธ
    if (this.cache.has(cacheKey)) {
      const cached = this.cache.get(cacheKey);
      
      // ์บ์‹œ๊ฐ€ ์œ ํšจํ•œ์ง€ ํ™•์ธ
      if (Date.now() - cached.timestamp < this.cacheTimeout) {
        console.log('๐Ÿ’พ ์บ์‹œ์—์„œ ๋กœ๋“œ:', url);
        return cached.data;
      } else {
        // ๋งŒ๋ฃŒ๋œ ์บ์‹œ ์‚ญ์ œ
        this.cache.delete(cacheKey);
      }
    }
    
    // ์ƒˆ๋กœ fetch
    console.log('๐ŸŒ ์„œ๋ฒ„์—์„œ ๋กœ๋“œ:', url);
    const response = await fetch(url, options);
    const data = await response.json();
    
    // ์บ์‹œ์— ์ €์žฅ
    this.cache.set(cacheKey, {
      data,
      timestamp: Date.now()
    });
    
    return data;
  }
  
  clearCache(pattern) {
    if (pattern) {
      // ํŒจํ„ด๊ณผ ์ผ์น˜ํ•˜๋Š” ์บ์‹œ๋งŒ ์‚ญ์ œ
      for (let key of this.cache.keys()) {
        if (key.includes(pattern)) {
          this.cache.delete(key);
        }
      }
    } else {
      // ์ „์ฒด ์บ์‹œ ์‚ญ์ œ
      this.cache.clear();
    }
  }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const router = new CachedRouter(routes);

// ๋ฐ์ดํ„ฐ fetch (์ž๋™์œผ๋กœ ์บ์‹ฑ๋จ)
const products = await router.fetchData('/api/products');

// ํŠน์ • ์บ์‹œ ์‚ญ์ œ
router.clearCache('/api/products');

4. ๊ฐ€์ƒ ์Šคํฌ๋กค๋ง

๊ธด ๋ชฉ๋ก์„ ๋ Œ๋”๋งํ•  ๋•Œ๋Š” ๊ฐ€์ƒ ์Šคํฌ๋กค๋ง์„ ์‚ฌ์šฉํ•˜๋ฉด ์„ฑ๋Šฅ์ด ์—„์ฒญ ์ข‹์•„์ ธ!

class VirtualList {
  constructor(container, items, itemHeight, renderItem) {
    this.container = container;
    this.items = items;
    this.itemHeight = itemHeight;
    this.renderItem = renderItem;
    this.visibleStart = 0;
    this.visibleEnd = 0;
    
    this.init();
  }
  
  init() {
    // ์ปจํ…Œ์ด๋„ˆ ๋†’์ด ๊ณ„์‚ฐ
    const containerHeight = this.container.clientHeight;
    const visibleCount = Math.ceil(containerHeight / this.itemHeight) + 1;
    
    // ์Šคํฌ๋กค ์ด๋ฒคํŠธ
    this.container.addEventListener('scroll', () => {
      this.update();
    });
    
    // ์ดˆ๊ธฐ ๋ Œ๋”๋ง
    this.update();
  }
  
  update() {
    const scrollTop = this.container.scrollTop;
    const containerHeight = this.container.clientHeight;
    
    // ๋ณด์ด๋Š” ๋ฒ”์œ„ ๊ณ„์‚ฐ
    this.visibleStart = Math.floor(scrollTop / this.itemHeight);
    this.visibleEnd = Math.ceil((scrollTop + containerHeight) / this.itemHeight);
    
    // ๋ฒ„ํผ ์ถ”๊ฐ€ (๋ถ€๋“œ๋Ÿฌ์šด ์Šคํฌ๋กค์„ ์œ„ํ•ด)
    const buffer = 3;
    this.visibleStart = Math.max(0, this.visibleStart - buffer);
    this.visibleEnd = Math.min(this.items.length, this.visibleEnd + buffer);
    
    this.render();
  }
  
  render() {
    const visibleItems = this.items.slice(this.visibleStart, this.visibleEnd);
    
    // ์ „์ฒด ๋†’์ด ์„ค์ • (์Šคํฌ๋กค๋ฐ”๋ฅผ ์œ„ํ•ด)
    const totalHeight = this.items.length * this.itemHeight;
    
    let html = `<div style="height: ${totalHeight}px; position: relative;">`;
    
    visibleItems.forEach((item, index) => {
      const actualIndex = this.visibleStart + index;
      const top = actualIndex * this.itemHeight;
      
      html += `
        <div style="
          position: absolute;
          top: ${top}px;
          height: ${this.itemHeight}px;
          width: 100%;
        ">
          ${this.renderItem(item, actualIndex)}
        </div>
      `;
    });
    
    html += '</div>';
    this.container.innerHTML = html;
  }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const routes = {
  '/products': {
    component: async () => {
      const products = await fetch('/api/products').then(r => r.json());
      
      // 10,000๊ฐœ ์•„์ดํ…œ๋„ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ!
      setTimeout(() => {
        const container = document.getElementById('product-list');
        new VirtualList(container, products, 80, (product, index) => `
          <div class="product-item">
            <h3>${product.name}</h3>
            <p>${product.price}์›</p>
          </div>
        `);
      }, 0);
      
      return `
        <h1>์ œํ’ˆ ๋ชฉ๋ก (${products.length}๊ฐœ)</h1>
        <div id="product-list" style="height: 600px; overflow-y: auto;">
          ๋กœ๋”ฉ ์ค‘...
        </div>
      `;
    }
  }
};

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™” ์ฒดํฌ๋ฆฌ์ŠคํŠธ


โœ… ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ…์œผ๋กœ ์ดˆ๊ธฐ ๋กœ๋”ฉ ์ตœ์†Œํ™”

โœ… ํ”„๋ฆฌํŽ˜์นญ์œผ๋กœ ์ฒด๊ฐ ์†๋„ ํ–ฅ์ƒ

โœ… ์บ์‹ฑ์œผ๋กœ ๋ถˆํ•„์š”ํ•œ ๋„คํŠธ์›Œํฌ ์š”์ฒญ ์ œ๊ฑฐ

โœ… ๊ฐ€์ƒ ์Šคํฌ๋กค๋ง์œผ๋กœ ๋Œ€๋Ÿ‰ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ

โœ… ์ด๋ฏธ์ง€ ๋ ˆ์ด์ง€ ๋กœ๋”ฉ

โœ… ๋ฒˆ๋“ค ํฌ๊ธฐ ์ตœ์†Œํ™” (Tree shaking)

โœ… CDN ํ™œ์šฉ

์„ฑ๋Šฅ ์ตœ์ ํ™” ํšจ๊ณผ ์ตœ์ ํ™” ์ „ 3.5์ดˆ ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ… 2.1์ดˆ ํ”„๋ฆฌํŽ˜์นญ ์ถ”๊ฐ€ 1.2์ดˆ ์บ์‹ฑ + ์ตœ์ ํ™” 0.5์ดˆ 75% ์†๋„ ํ–ฅ์ƒ ๋ฒˆ๋“ค ํฌ๊ธฐ -60% ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ -40%

๐Ÿงช ํ…Œ์ŠคํŒ…๊ณผ ๋””๋ฒ„๊น…

๋ผ์šฐํ„ฐ๋ฅผ ๋งŒ๋“ค์—ˆ์œผ๋ฉด ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•ด์•ผ๊ฒ ์ง€? ํ…Œ์ŠคํŒ… ์ „๋žต์„ ์•Œ์•„๋ณด์ž!

1. ์œ ๋‹› ํ…Œ์ŠคํŠธ

// Jest๋ฅผ ์‚ฌ์šฉํ•œ ๋ผ์šฐํ„ฐ ํ…Œ์ŠคํŠธ
describe('Router', () => {
  let router;
  
  beforeEach(() => {
    // DOM ์ดˆ๊ธฐํ™”
    document.body.innerHTML = '<div id="app"></div>';
    
    // ๋ผ์šฐํ„ฐ ์ƒ์„ฑ
    router = new AdvancedRouter({
      '/': { component: () => 'Home' },
      '/about': { component: () => 'About' },
      '/user/:id': { component: ({ params }) => `User ${params.id}` }
    });
  });
  
  test('๊ธฐ๋ณธ ๊ฒฝ๋กœ ๋ Œ๋”๋ง', () => {
    router.handleRoute('/');
    expect(document.getElementById('app').innerHTML).toBe('Home');
  });
  
  test('๋™์  ํŒŒ๋ผ๋ฏธํ„ฐ ํŒŒ์‹ฑ', () => {
    router.handleRoute('/user/123');
    expect(document.getElementById('app').innerHTML).toBe('User 123');
  });
  
  test('์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ ํŒŒ์‹ฑ', () => {
    router.handleRoute('/search?q=test&sort=latest');
    expect(router.query).toEqual({ q: 'test', sort: 'latest' });
  });
  
  test('404 ์ฒ˜๋ฆฌ', () => {
    router.handleRoute('/nonexistent');
    expect(document.getElementById('app').innerHTML).toContain('404');
  });
  
  test('๋„ค๋น„๊ฒŒ์ด์…˜ ๊ฐ€๋“œ', async () => {
    let guardCalled = false;
    
    router.beforeEach(() => {
      guardCalled = true;
      return false; // ๋„ค๋น„๊ฒŒ์ด์…˜ ์ทจ์†Œ
    });
    
    await router.handleRoute('/about');
    expect(guardCalled).toBe(true);
    expect(document.getElementById('app').innerHTML).not.toBe('About');
  });
});

2. E2E ํ…Œ์ŠคํŠธ

// Cypress๋ฅผ ์‚ฌ์šฉํ•œ E2E ํ…Œ์ŠคํŠธ
describe('SPA Navigation', () => {
  beforeEach(() => {
    cy.visit('/');
  });
  
  it('ํ™ˆ์—์„œ ์†Œ๊ฐœ ํŽ˜์ด์ง€๋กœ ์ด๋™', () => {
    cy.contains('์†Œ๊ฐœ').click();
    cy.url().should('include', '/about');
    cy.contains('์†Œ๊ฐœ ํŽ˜์ด์ง€').should('be.visible');
  });
  
  it('๋’ค๋กœ ๊ฐ€๊ธฐ ๋ฒ„ํŠผ ์ž‘๋™', () => {
    cy.contains('์†Œ๊ฐœ').click();
    cy.go('back');
    cy.url().should('eq', Cypress.config().baseUrl + '/');
  });
  
  it('์ง์ ‘ URL ์ž…๋ ฅ', () => {
    cy.visit('/user/123');
    cy.contains('์‚ฌ์šฉ์ž ID: 123').should('be.visible');
  });
  
  it('์ธ์ฆ ๊ฐ€๋“œ', () => {
    cy.visit('/dashboard');
    cy.url().should('include', '/login');
    cy.contains('๋กœ๊ทธ์ธ').should('be.visible');
  });
  
  it('ํŽ˜์ด์ง€ ์ „ํ™˜ ์• ๋‹ˆ๋ฉ”์ด์…˜', () => {
    cy.contains('์†Œ๊ฐœ').click();
    cy.get('#app').should('have.class', 'page-transition');
  });
});

3. ๋””๋ฒ„๊น… ๋„๊ตฌ

// ๋ผ์šฐํ„ฐ ๋””๋ฒ„๊น… ํ”Œ๋Ÿฌ๊ทธ์ธ
class RouterDebugger {
  constructor(router) {
    this.router = router;
    this.logs = [];
    this.enabled = true;
    
    this.attachDebugger();
  }
  
  attachDebugger() {
    // ๋„ค๋น„๊ฒŒ์ด์…˜ ๋กœ๊น…
    this.router.beforeEach((to, from) => {
      if (this.enabled) {
        const log = {
          type: 'navigation',
          from,
          to,
          timestamp: new Date().toISOString(),
          params: this.router.params,
          query: this.router.query
        };
        
        this.logs.push(log);
        console.log('๐Ÿ” [Router Debug]', log);
      }
      
      return true;
    });
    
    // ์—๋Ÿฌ ๋กœ๊น…
    const originalRender = this.router.render.bind(this.router);
    this.router.render = async (...args) => {
      try {
        await originalRender(...args);
      } catch (error) {
        const log = {
          type: 'error',
          error: error.message,
          stack: error.stack,
          timestamp: new Date().toISOString()
        };
        
        this.logs.push(log);
        console.error('โŒ [Router Error]', log);
        throw error;
      }
    };
  }
  
  // ๋””๋ฒ„๊ทธ ํŒจ๋„ ํ‘œ์‹œ
  showDebugPanel() {
    const panel = document.createElement('div');
    panel.id = 'router-debug-panel';
    panel.style.cssText = `
      position: fixed;
      bottom: 20px;
      right: 20px;
      width: 400px;
      max-height: 500px;
      background: white;
      border: 2px solid #667eea;
      border-radius: 12px;
      padding: 15px;
      overflow-y: auto;
      box-shadow: 0 4px 12px rgba(0,0,0,0.15);
      z-index: 10000;
      font-family: monospace;
      font-size: 12px;
    `;
    
    let html = `
      <div style="display: flex; justify-content: space-between; margin-bottom: 10px;">
        <strong>๐Ÿ” Router Debug</strong>
        <button onclick="document.getElementById('router-debug-panel').remove()">โœ•</button>
      </div>
      <div>
        <strong>Current Route:</strong> ${this.router.currentPath}<br>
        <strong>Params:</strong> ${JSON.stringify(this.router.params)}<br>
        <strong>Query:</strong> ${JSON.stringify(this.router.query)}
      </div>
      <hr>
      <div><strong>Navigation History:</strong></div>
    `;
    
    this.logs.slice(-10).reverse().forEach(log => {
      const color = log.type === 'error' ? '#ef4444' : '#667eea';
      html += `
        <div style="margin: 5px 0; padding: 5px; background: #f3f4f6; border-radius: 4px;">
          <div style="color: ${color}; font-weight: bold;">${log.type.toUpperCase()}</div>
          <div>${log.from || ''} โ†’ ${log.to || ''}</div>
          <div style="font-size: 10px; color: #6b7280;">${log.timestamp}</div>
        </div>
      `;
    });
    
    panel.innerHTML = html;
    document.body.appendChild(panel);
  }
  
  // ๋กœ๊ทธ ๋‚ด๋ณด๋‚ด๊ธฐ
  exportLogs() {
    const dataStr = JSON.stringify(this.logs, null, 2);
    const dataBlob = new Blob([dataStr], { type: 'application/json' });
    const url = URL.createObjectURL(dataBlob);
    
    const link = document.createElement('a');
    link.href = url;
    link.download = `router-logs-${Date.now()}.json`;
    link.click();
  }
  
  // ์„ฑ๋Šฅ ๋ถ„์„
  analyzePerformance() {
    const navigationLogs = this.logs.filter(l => l.type === 'navigation');
    
    return {
      totalNavigations: navigationLogs.length,
      averageTime: '๊ณ„์‚ฐ ํ•„์š”',
      mostVisited: this.getMostVisitedRoute(navigationLogs),
      errorRate: (this.logs.filter(l => l.type === 'error').length / this.logs.length * 100).toFixed(2) + '%'
    };
  }
  
  getMostVisitedRoute(logs) {
    const counts = {};
    logs.forEach(log => {
      counts[log.to] = (counts[log.to] || 0) + 1;
    });
    
    return Object.entries(counts).sort((a, b) => b[1] - a[1])[0]?.[0] || 'N/A';
  }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const router = new AdvancedRouter(routes);
const debugger = new RouterDebugger(router);

// ๊ฐœ๋ฐœ ๋ชจ๋“œ์—์„œ๋งŒ ๋””๋ฒ„๊ทธ ํŒจ๋„ ํ‘œ์‹œ
if (process.env.NODE_ENV === 'development') {
  // Ctrl+Shift+D๋กœ ๋””๋ฒ„๊ทธ ํŒจ๋„ ํ† ๊ธ€
  document.addEventListener('keydown', (e) => {
    if (e.ctrlKey && e.shiftKey && e.key === 'D') {
      debugger.showDebugPanel();
    }
  });
}
๐Ÿ’ก ๋””๋ฒ„๊น… ํŒ:
โ€ข Chrome DevTools์˜ Network ํƒญ์—์„œ ๋ผ์šฐํŠธ ๋ณ€๊ฒฝ ์‹œ ๋„คํŠธ์›Œํฌ ์š”์ฒญ ํ™•์ธ
โ€ข React DevTools๋‚˜ Vue DevTools ๊ฐ™์€ ํ”„๋ ˆ์ž„์›Œํฌ ์ „์šฉ ๋„๊ตฌ ํ™œ์šฉ
โ€ข Performance ํƒญ์œผ๋กœ ๋ Œ๋”๋ง ์„ฑ๋Šฅ ๋ถ„์„
โ€ข Console์— ๋ผ์šฐํŠธ ๋ณ€๊ฒฝ ๋กœ๊ทธ ๋‚จ๊ธฐ๊ธฐ

๐ŸŒ SEO์™€ ๋ฉ”ํƒ€ ํƒœ๊ทธ ๊ด€๋ฆฌ

SPA์˜ ๊ฐ€์žฅ ํฐ ์•ฝ์ ์ด SEO์•ผ. ํ•˜์ง€๋งŒ ์ œ๋Œ€๋กœ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋ฌธ์ œ์—†์–ด!

1. ๋™์  ๋ฉ”ํƒ€ ํƒœ๊ทธ ๊ด€๋ฆฌ

class SEOManager {
  constructor() {
    this.defaultMeta = {
      title: '๋‚ด ๋ฉ‹์ง„ SPA',
      description: 'JavaScript๋กœ ๋งŒ๋“  ์‹ฑ๊ธ€ ํŽ˜์ด์ง€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜',
      keywords: 'SPA, JavaScript, ๋ผ์šฐํŒ…',
      ogImage: '/images/og-default.jpg',
      ogType: 'website'
    };
  }
  
  updateMeta(meta = {}) {
    const finalMeta = { ...this.defaultMeta, ...meta };
    
    // ํŽ˜์ด์ง€ ํƒ€์ดํ‹€
    document.title = finalMeta.title;
    
    // ๋ฉ”ํƒ€ ํƒœ๊ทธ ์—…๋ฐ์ดํŠธ
    this.setMetaTag('description', finalMeta.description);
    this.setMetaTag('keywords', finalMeta.keywords);
    
    // Open Graph ํƒœ๊ทธ (์†Œ์…œ ๋ฏธ๋””์–ด ๊ณต์œ ์šฉ)
    this.setMetaTag('og:title', finalMeta.title, 'property');
    this.setMetaTag('og:description', finalMeta.description, 'property');
    this.setMetaTag('og:image', finalMeta.ogImage, 'property');
    this.setMetaTag('og:type', finalMeta.ogType, 'property');
    this.setMetaTag('og:url', window.location.href, 'property');
    
    // Twitter ์นด๋“œ
    this.setMetaTag('twitter:card', 'summary_large_image', 'name');
    this.setMetaTag('twitter:title', finalMeta.title, 'name');
    this.setMetaTag('twitter:description', finalMeta.description, 'name');
    this.setMetaTag('twitter:image', finalMeta.ogImage, 'name');
    
    // Canonical URL
    this.setCanonicalURL(window.location.href);
  }
  
  setMetaTag(name, content, attribute = 'name') {
    let element = document.querySelector(`meta[${attribute}="${name}"]`);
    
    if (!element) {
      element = document.createElement('meta');
      element.setAttribute(attribute, name);
      document.head.appendChild(element);
    }
    
    element.setAttribute('content', content);
  }
  
  setCanonicalURL(url) {
    let link = document.querySelector('link[rel="canonical"]');
    
    if (!link) {
      link = document.createElement('link');
      link.setAttribute('rel', 'canonical');
      document.head.appendChild(link);
    }
    
    link.setAttribute('href', url);
  }
  
  // ๊ตฌ์กฐํ™”๋œ ๋ฐ์ดํ„ฐ (JSON-LD)
  setStructuredData(data) {
    let script = document.querySelector('script[type="application/ld+json"]');
    
    if (!script) {
      script = document.createElement('script');
      script.type = 'application/ld+json';
      document.head.appendChild(script);
    }
    
    script.textContent = JSON.stringify(data);
  }
}

const seoManager = new SEOManager();

// ๋ผ์šฐํ„ฐ์— SEO ํ†ตํ•ฉ
const routes = {
  '/': {
    component: () => '...',
    meta: {
      title: 'ํ™ˆ - ์žฌ๋Šฅ๋„ท',
      description: '๋‹ค์–‘ํ•œ ์žฌ๋Šฅ์„ ๊ณต์œ ํ•˜๊ณ  ๊ฑฐ๋ž˜ํ•˜๋Š” ํ”Œ๋žซํผ',
      keywords: '์žฌ๋Šฅ๊ณต์œ , ํ”„๋ฆฌ๋žœ์„œ, ์™ธ์ฃผ',
      ogImage: '/images/home-og.jpg'
    }
  },
  
  '/blog/:slug': {
    component: async ({ params }) => {
      // ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ
      const post = await fetch(`/api/posts/${params.slug}`).then(r => r.json());
      
      // SEO ๋ฉ”ํƒ€ ์—…๋ฐ์ดํŠธ
      seoManager.updateMeta({
        title: `${post.title} - ์žฌ๋Šฅ๋„ท ๋ธ”๋กœ๊ทธ`,
        description: post.excerpt,
        keywords: post.tags.join(', '),
        ogImage: post.coverImage,
        ogType: 'article'
      });
      
      // ๊ตฌ์กฐํ™”๋œ ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€
      seoManager.setStructuredData({
        '@context': 'https://schema.org',
        '@type': 'BlogPosting',
        'headline': post.title,
        'image': post.coverImage,
        'datePublished': post.publishedAt,
        'dateModified': post.updatedAt,
        'author': {
          '@type': 'Person',
          'name': post.author.name
        },
        'publisher': {
          '@type': 'Organization',
          'name': '์žฌ๋Šฅ๋„ท',
          'logo': {
            '@type': 'ImageObject',
            'url': 'https://www.jaenung.net/logo.png'
          }
        },
        'description': post.excerpt
      });
      
      return `
        <article>
          <h1>${post.title}</h1>
          <div>${post.content}</div>
        </article>
      `;
    }
  }
};

// ๋ผ์šฐํ„ฐ์— SEO ํ›… ์ถ”๊ฐ€
router.afterEach((to) => {
  const route = routes[to];
  if (route?.meta) {
    seoManager.updateMeta(route.meta);
  }
});

2. ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง (SSR)

์ง„์งœ ์™„๋ฒฝํ•œ SEO๋ฅผ ์›ํ•œ๋‹ค๋ฉด SSR์„ ๊ณ ๋ คํ•ด๋ด!

// Node.js + Express๋กœ SSR ๊ตฌํ˜„
const express = require('express');
const app = express();

// ๋ผ์šฐํŠธ๋ณ„ ๋ Œ๋”๋ง ํ•จ์ˆ˜
const renderPage = (route, data = {}) => {
  const routes = {
    '/': () => `
      <!DOCTYPE html>
      <html>
      <head>
        <title>ํ™ˆ - ์žฌ๋Šฅ๋„ท</title>
        <meta name="description" content="๋‹ค์–‘ํ•œ ์žฌ๋Šฅ์„ ๊ณต์œ ํ•˜์„ธ์š”">
      </head>
      <body>
        <div id="app">
          <h1>ํ™ˆ ํŽ˜์ด์ง€</h1>
          <p>์„œ๋ฒ„์—์„œ ๋ Œ๋”๋ง๋œ ์ฝ˜ํ…์ธ </p>
        </div>
        <script src="/js/app.js"></script>
      </body>
      </html>
    `,
    
    '/blog/:slug': () => `
      <!DOCTYPE html>
      <html>
      <head>
        <title>${data.title} - ์žฌ๋Šฅ๋„ท ๋ธ”๋กœ๊ทธ</title>
        <meta name="description" content="${data.excerpt}">
        <meta property="og:title" content="${data.title}">
        <meta property="og:image" content="${data.coverImage}">
      </head>
      <body>
        <div id="app">
          <article>
            <h1>${data.title}</h1>
            <div>${data.content}</div>
          </article>
        </div>
        <script>
          // ํด๋ผ์ด์–ธํŠธ์—์„œ hydration
          window.__INITIAL_DATA__ = ${JSON.stringify(data)};
        </script>
        <script src="/js/app.js"></script>
      </body>
      </html>
    `
  };
  
  const renderer = routes[route];
  return renderer ? renderer() : routes['/']();
};

// ๋ผ์šฐํŠธ ํ•ธ๋“ค๋Ÿฌ
app.get('/blog/:slug', async (req, res) => {
  try {
    // ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ํฌ์ŠคํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ
    const post = await getPostBySlug(req.params.slug);
    
    if (!post) {
      return res.status(404).send('ํฌ์ŠคํŠธ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค');
    }
    
    // ์„œ๋ฒ„์—์„œ HTML ๋ Œ๋”๋ง
    const html = renderPage('/blog/:slug', post);
    res.send(html);
  } catch (error) {
    console.error(error);
    res.status(500).send('์„œ๋ฒ„ ์˜ค๋ฅ˜');
  }
});

// ๊ธฐ๋ณธ ๋ผ์šฐํŠธ
app.get('*', (req, res) => {
  const html = renderPage(req.path);
  res.send(html);
});

app.listen(3000, () => {
  console.log('SSR ์„œ๋ฒ„ ์‹คํ–‰ ์ค‘! ๐Ÿš€');
});
โš ๏ธ SSR vs CSR ์„ ํƒ ๊ฐ€์ด๋“œ:
SSR์ด ์ข‹์€ ๊ฒฝ์šฐ:
โ€ข SEO๊ฐ€ ๋งค์šฐ ์ค‘์š”ํ•œ ๊ฒฝ์šฐ (๋ธ”๋กœ๊ทธ, ๋‰ด์Šค, ์ด์ปค๋จธ์Šค)
โ€ข ์ดˆ๊ธฐ ๋กœ๋”ฉ ์†๋„๊ฐ€ ์ค‘์š”ํ•œ ๊ฒฝ์šฐ
โ€ข ์†Œ์…œ ๋ฏธ๋””์–ด ๊ณต์œ ๊ฐ€ ๋งŽ์€ ๊ฒฝ์šฐ

CSR์ด ์ข‹์€ ๊ฒฝ์šฐ:
โ€ข ์ธํ„ฐ๋ž™์…˜์ด ๋งŽ์€ ์•ฑ (๋Œ€์‹œ๋ณด๋“œ, ๊ด€๋ฆฌ์ž ํŽ˜์ด์ง€)
โ€ข ๋กœ๊ทธ์ธ ํ›„์—๋งŒ ์‚ฌ์šฉํ•˜๋Š” ์„œ๋น„์Šค
โ€ข ์„œ๋ฒ„ ๋ฆฌ์†Œ์Šค๊ฐ€ ์ œํ•œ์ ์ธ ๊ฒฝ์šฐ

๐Ÿ“ฑ ๋ชจ๋ฐ”์ผ ์ตœ์ ํ™”

๋ชจ๋ฐ”์ผ์—์„œ๋„ ์™„๋ฒฝํ•˜๊ฒŒ ์ž‘๋™ํ•˜๋Š” ๋„ค๋น„๊ฒŒ์ด์…˜์„ ๋งŒ๋“ค์–ด๋ณด์ž!

1. ํ„ฐ์น˜ ์ œ์Šค์ฒ˜ ์ง€์›

class TouchNavigationRouter extends AdvancedRouter {
  constructor(routes, options = {}) {
    super(routes, options);
    this.setupTouchGestures();
  }
  
  setupTouchGestures() {
    let touchStartX = 0;
    let touchEndX = 0;
    
    document.addEventListener('touchstart', (e) => {
      touchStartX = e.changedTouches[0].screenX;
    }, { passive: true });
    
    document.addEventListener('touchend', (e) => {
      touchEndX = e.changedTouches[0].screenX;
      this.handleSwipe();
    }, { passive: true });
  }
  
  handleSwipe() {
    const swipeThreshold = 100;
    const diff = touchStartX - touchEndX;
    
    if (Math.abs(diff) > swipeThreshold) {
      if (diff > 0) {
        // ์™ผ์ชฝ์œผ๋กœ ์Šค์™€์ดํ”„ (์•ž์œผ๋กœ ๊ฐ€๊ธฐ)
        this.forward();
      } else {
        // ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์Šค์™€์ดํ”„ (๋’ค๋กœ ๊ฐ€๊ธฐ)
        this.back();
      }
    }
  }
}

2. ๋ชจ๋ฐ”์ผ ๋ฉ”๋‰ด

// ๋ฐ˜์‘ํ˜• ๋„ค๋น„๊ฒŒ์ด์…˜ ์ปดํฌ๋„ŒํŠธ
function createMobileNav() {
  return `
    <style>
      .mobile-nav {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 300px;
        height: 100vh;
        background: white;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        transition: left 0.3s ease;
        z-index: 1000;
      }
      
      .mobile-nav.open {
        left: 0;
      }
      
      .mobile-nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0,0,0,0.5);
        display: none;
        z-index: 999;
      }
      
      .mobile-nav-overlay.show {
        display: block;
      }
      
      .hamburger {
        display: none;
        position: fixed;
        top: 20px;
        left: 20px;
        z-index: 1001;
        background: white;
        border: none;
        padding: 10px;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        cursor: pointer;
      }
      
      @media (max-width: 768px) {
        .hamburger {
          display: block;
        }
        
        .desktop-nav {
          display: none;
        }
      }
    </style>
    
    <button class="hamburger" onclick="toggleMobileNav()">
      โ˜ฐ
    </button>
    
    <div class="mobile-nav-overlay" onclick="toggleMobileNav()"></div>
    
    <nav class="mobile-nav">
      <div style="padding: 20px;">
        <h2>๋ฉ”๋‰ด</h2>
        <ul style="list-style: none; padding: 0;">
          <li><a href="/" data-link onclick="toggleMobileNav()">ํ™ˆ</a></li>
          <li><a href="/about" data-link onclick="toggleMobileNav()">์†Œ๊ฐœ</a></li>
          <li><a href="/products" data-link onclick="toggleMobileNav()">์ œํ’ˆ</a></li>
          <li><a href="/contact" data-link onclick="toggleMobileNav()">์—ฐ๋ฝ์ฒ˜</a></li>
        </ul>
      </div>
    </nav>
    
    <script>
      function toggleMobileNav() {
        const nav = document.querySelector('.mobile-nav');
        const overlay = document.querySelector('.mobile-nav-overlay');
        
        nav.classList.toggle('open');
        overlay.classList.toggle('show');
      }
    </script>
  `;
}

3. PWA ์ง€์›

// Service Worker๋กœ ์˜คํ”„๋ผ์ธ ์ง€์›
// sw.js
const CACHE_NAME = 'spa-cache-v1';
const urlsToCache = [
  '/',
  '/css/style.css',
  '/js/app.js',
  '/js/router.js'
];

self.addEventListener('install', (event) => {
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then((cache) => cache.addAll(urlsToCache))
  );
});

self.addEventListener('fetch', (event) => {
  event.respondWith(
    caches.match(event.request)
      .then((response) => {
        // ์บ์‹œ์— ์žˆ์œผ๋ฉด ์บ์‹œ์—์„œ, ์—†์œผ๋ฉด ๋„คํŠธ์›Œํฌ์—์„œ
        return response || fetch(event.request);
      })
  );
});

// ์•ฑ์—์„œ Service Worker ๋“ฑ๋ก
if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/sw.js')
    .then((registration) => {
      console.log('โœ… Service Worker ๋“ฑ๋ก ์„ฑ๊ณต!', registration);
    })
    .catch((error) => {
      console.error('โŒ Service Worker ๋“ฑ๋ก ์‹คํŒจ:', error);
    });
}

๐ŸŽ“ ์‹ค์ „ ํ”„๋กœ์ ํŠธ: ์™„์ „ํ•œ SPA ๋งŒ๋“ค๊ธฐ

์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์šด ๋ชจ๋“  ๊ฑธ ์ข…ํ•ฉํ•ด์„œ ์‹ค์ „ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž! ๊ฐ„๋‹จํ•œ ๋ธ”๋กœ๊ทธ SPA๋ฅผ ๊ตฌํ˜„ํ• ๊ฒŒ.

// ์™„์ „ํ•œ ๋ธ”๋กœ๊ทธ SPA ๊ตฌํ˜„
class BlogSPA {
  constructor() {
    this.router = null;
    this.seoManager = new SEOManager();
    this.auth = new AuthManager();
    this.init();
  }
  
  init() {
    // ๋ผ์šฐํŠธ ์ •์˜
    const routes = {
      '/': {
        component: this.renderHome.bind(this),
        meta: {
          title: 'ํ™ˆ - ๋‚ด ๋ธ”๋กœ๊ทธ',
          description: 'JavaScript๋กœ ๋งŒ๋“  ๋ธ”๋กœ๊ทธ'
        }
      },
      
      '/posts': {
        component: this.renderPostList.bind(this),
        meta: {
          title: 'ํฌ์ŠคํŠธ ๋ชฉ๋ก'
        }
      },
      
      '/post/:slug': {
        component: this.renderPost.bind(this)
      },
      
      '/write': {
        component: this.renderEditor.bind(this),
        meta: {
          requiresAuth: true
        }
      },
      
      '/login': {
        component: this.renderLogin.bind(this)
      },
      
      '/404': {
        component: () => this.render404()
      }
    };
    
    // ๋ผ์šฐํ„ฐ ์ƒ์„ฑ
    this.router = new AdvancedRouter(routes, { mode: 'history' });
    
    // ์ธ์ฆ ๊ฐ€๋“œ
    this.router.beforeEach((to, from) => {
      const route = routes[to];
      
      if (route?.meta?.requiresAuth && !this.auth.isAuthenticated()) {
        alert('๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค!');
        return '/login';
      }
      
      return true;
    });
    
    // SEO ์—…๋ฐ์ดํŠธ
    this.router.afterEach((to) => {
      const route = routes[to];
      if (route?.meta) {
        this.seoManager.updateMeta(route.meta);
      }
    });
  }
  
  async renderHome() {
    const recentPosts = await this.fetchRecentPosts();
    
    return `
      <div class="home-page">
        ${this.renderHeader()}
        
        <section class="hero">
          <h1>ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค! ๐Ÿ‘‹</h1>
          <p>JavaScript์™€ ์›น ๊ฐœ๋ฐœ์— ๋Œ€ํ•œ ์ด์•ผ๊ธฐ๋ฅผ ๋‚˜๋ˆ•๋‹ˆ๋‹ค.</p>
        </section>
        
        <section class="recent-posts">
          <h2>์ตœ๊ทผ ํฌ์ŠคํŠธ</h2>
          <div class="post-grid">
            ${recentPosts.map(post => `
              <article class="post-card">
                <img src="${post.coverImage}" alt="${post.title}">
                <h3><a href="/post/${post.slug}" data-link>${post.title}</a></h3>
                <p>${post.excerpt}</p>
                <div class="post-meta">
                  <span>${post.author}</span>
                  <span>${post.date}</span>
                </div>
              </article>
            `).join('')}
          </div>
        </section>
        
        ${this.renderFooter()}
      </div>
    `;
  }
  
  async renderPostList({ query }) {
    const page = parseInt(query.page) || 1;
    const category = query.category || 'all';
    
    const posts = await this.fetchPosts({ page, category });
    
    return `
      <div class="post-list-page">
        ${this.renderHeader()}
        
        <div class="container">
          <h1>ํฌ์ŠคํŠธ ๋ชฉ๋ก</h1>
          
          <div class="filters">
            <a href="/posts?category=all" data-link>์ „์ฒด</a>
            <a href="/posts?category=javascript" data-link>JavaScript</a>
            <a href="/posts?category=css" data-link>CSS</a>
            <a href="/posts?category=react" data-link>React</a>
          </div>
          
          <div class="posts">
            ${posts.map(post => `
              <article>
                <h2><a href="/post/${post.slug}" data-link>${post.title}</a></h2>
                <p>${post.excerpt}</p>
                <a href="/post/${post.slug}" data-link>๋” ์ฝ๊ธฐ โ†’</a>
              </article>
            `).join('')}
          </div>
          
          <div class="pagination">
            ${page > 1 ? `<a href="/posts?page=${page-1}&category=${category}" data-link>โ† ์ด์ „</a>` : ''}
            <span>ํŽ˜์ด์ง€ ${page}</span>
            <a href="/posts?page=${page+1}&category=${category}" data-link>๋‹ค์Œ โ†’</a>
          </div>
        </div>
        
        ${this.renderFooter()}
      </div>
    `;
  }
  
  async renderPost({ params }) {
    const post = await this.fetchPost(params.slug);
    
    if (!post) {
      this.router.navigate('/404');
      return;
    }
    
    // SEO ๋ฉ”ํƒ€ ์—…๋ฐ์ดํŠธ
    this.seoManager.updateMeta({
      title: `${post.title} - ๋‚ด ๋ธ”๋กœ๊ทธ`,
      description: post.excerpt,
      ogImage: post.coverImage,
      ogType: 'article'
    });
    
    return `
      <div class="post-page">
        ${this.renderHeader()}
        
        <article class="post-content">
          <header>
            <h1>${post.title}</h1>
            <div class="post-meta">
              <span>์ž‘์„ฑ์ž: ${post.author}</span>
              <span>๋‚ ์งœ: ${post.date}</span>
              <span>์นดํ…Œ๊ณ ๋ฆฌ: ${post.category}</span>
            </div>
          </header>
          
          <img src="${post.coverImage}" alt="${post.title}" class="cover-image">
          
          <div class="content">
            ${post.content}
          </div>
          
          <footer>
            <div class="tags">
              ${post.tags.map(tag => `<span class="tag">#${tag}</span>`).join('')}
            </div>
            
            <div class="share">
              <button onclick="sharePost('${post.slug}')">๊ณต์œ ํ•˜๊ธฐ ๐Ÿ“ค</button>
            </div>
          </footer>
        </article>
        
        <section class="comments">
          <h2>๋Œ“๊ธ€</h2>
          <div id="comments-container"></div>
        </section>
        
        ${this.renderFooter()}
      </div>
    `;
  }
  
  renderEditor() {
    return `
      <div class="editor-page">
        ${this.renderHeader()}
        
        <div class="container">
          <h1>์ƒˆ ํฌ์ŠคํŠธ ์ž‘์„ฑ โœ๏ธ</h1>
          
          <form id="post-form">
            <input type="text" id="title" placeholder="์ œ๋ชฉ" required>
            <input type="text" id="slug" placeholder="URL ์Šฌ๋Ÿฌ๊ทธ" required>
            <select id="category">
              <option value="javascript">JavaScript</option>
              <option value="css">CSS</option>
              <option value="react">React</option>
            </select>
            <textarea id="content" placeholder="๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜์„ธ์š”..." rows="20"></textarea>
            <input type="text" id="tags" placeholder="ํƒœ๊ทธ (์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„)">
            <button type="submit">๋ฐœํ–‰ํ•˜๊ธฐ</button>
          </form>
        </div>
        
        ${this.renderFooter()}
        
        <script>
          document.getElementById('post-form').addEventListener('submit', async (e) => {
            e.preventDefault();
            
            const post = {
              title: document.getElementById('title').value,
              slug: document.getElementById('slug').value,
              category: document.getElementById('category').value,
              content: document.getElementById('content').value,
              tags: document.getElementById('tags').value.split(',').map(t => t.trim())
            };
            
            const success = await blogSPA.savePost(post);
            if (success) {
              alert('ํฌ์ŠคํŠธ๊ฐ€ ๋ฐœํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค!');
              router.navigate('/post/' + post.slug);
            }
          });
        </script>
      </div>
    `;
  }
  
  renderLogin() {
    return `
      <div class="login-page">
        <div class="login-container">
          <h1>๋กœ๊ทธ์ธ ๐Ÿ”</h1>
          
          <form id="login-form">
            <input type="text" id="username" placeholder="์‚ฌ์šฉ์ž๋ช…" required>
            <input type="password" id="password" placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" required>
            <button type="submit">๋กœ๊ทธ์ธ</button>
          </form>
          
          <p><a href="/" data-link>โ† ํ™ˆ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ</a></p>
        </div>
        
        <script>
          document.getElementById('login-form').addEventListener('submit', async (e) => {
            e.preventDefault();
            
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            
            const success = await auth.login(username, password);
            if (success) {
              router.navigate('/');
            } else {
              alert('๋กœ๊ทธ์ธ ์‹คํŒจ!');
            }
          });
        </script>
      </div>
    `;
  }
  
  render404() {
    return `
      <div class="error-page">
        ${this.renderHeader()}
        
        <div class="error-content">
          <h1>404</h1>
          <p>ํŽ˜์ด์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค ๐Ÿ˜ข</p>
          <a href="/" data-link>ํ™ˆ์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ</a>
        </div>
        
        ${this.renderFooter()}
      </div>
    `;
  }
  
  renderHeader() {
    const isLoggedIn = this.auth.isAuthenticated();
    
    return `
      <header class="site-header">
        <div class="container">
          <a href="/" data-link class="logo">๋‚ด ๋ธ”๋กœ๊ทธ</a>
          
          <nav>
            <a href="/" data-link>ํ™ˆ</a>
            <a href="/posts" data-link>ํฌ์ŠคํŠธ</a>
            ${isLoggedIn ? `
              <a href="/write" data-link>๊ธ€์“ฐ๊ธฐ</a>
              <button onclick="auth.logout(); router.navigate('/');">๋กœ๊ทธ์•„์›ƒ</button>
            ` : `
              <a href="/login" data-link>๋กœ๊ทธ์ธ</a>
            `}
          </nav>
        </div>
      </header>
    `;
  }
  
  renderFooter() {
    return `
      <footer class="site-footer">
        <div class="container">
          <p>ยฉ 2024 ๋‚ด ๋ธ”๋กœ๊ทธ. Made with โค๏ธ and JavaScript</p>
          <p>์žฌ๋Šฅ๋„ท์—์„œ ๋” ๋งŽ์€ ๊ฐœ๋ฐœ ํŒ์„ ๋งŒ๋‚˜๋ณด์„ธ์š”!</p>
        </div>
      </footer>
    `;
  }
  
  // API ๋ฉ”์„œ๋“œ๋“ค
  async fetchRecentPosts() {
    // ์‹ค์ œ๋กœ๋Š” API ํ˜ธ์ถœ
    return [
      {
        slug: 'javascript-routing',
        title: 'JavaScript ๋ผ์šฐํŒ… ์™„๋ฒฝ ๊ฐ€์ด๋“œ',
        excerpt: 'SPA ๋ผ์šฐํŒ…์˜ ๋ชจ๋“  ๊ฒƒ',
        coverImage: '/images/post1.jpg',
        author: '๊ฐœ๋ฐœ์ž',
        date: '2024-01-15'
      }
      // ... ๋” ๋งŽ์€ ํฌ์ŠคํŠธ
    ];
  }
  
  async fetchPosts({ page, category }) {
    // API ํ˜ธ์ถœ
    return [];
  }
  
  async fetchPost(slug) {
    // API ํ˜ธ์ถœ
    return null;
  }
  
  async savePost(post) {
    // API ํ˜ธ์ถœ
    return true;
  }
}

// ์•ฑ ์‹œ์ž‘!
const blogSPA = new BlogSPA();

๐ŸŽ‰ ์ถ•ํ•˜ํ•ด! ์™„์ „ํ•œ ๋ธ”๋กœ๊ทธ SPA๋ฅผ ๋งŒ๋“ค์—ˆ์–ด!


์ด ํ”„๋กœ์ ํŠธ์—๋Š” ๋‹ค์Œ ๊ธฐ๋Šฅ๋“ค์ด ๋ชจ๋‘ ํฌํ•จ๋˜์–ด ์žˆ์–ด:


โœ… ๋ผ์šฐํŒ… (History API)

โœ… ๋™์  ๋ผ์šฐํŠธ ํŒŒ๋ผ๋ฏธํ„ฐ

โœ… ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ

โœ… ์ธ์ฆ ์‹œ์Šคํ…œ

โœ… SEO ์ตœ์ ํ™”

โœ… ๋„ค๋น„๊ฒŒ์ด์…˜ ๊ฐ€๋“œ

โœ… ๋ฐ˜์‘ํ˜• ๋””์ž์ธ

โœ… ํŽ˜์ด์ง€๋„ค์ด์…˜


์ด ์ฝ”๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž์‹ ๋งŒ์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ด! ๐Ÿ’ช

๐Ÿš€ ๋‹ค์Œ ๋‹จ๊ณ„์™€ ํ•™์Šต ๋ฆฌ์†Œ์Šค

์—ฌ๊ธฐ๊นŒ์ง€ ์™”๋‹ค๋ฉด ์ •๋ง ๋Œ€๋‹จํ•ด! ํ•˜์ง€๋งŒ ๋ฐฐ์›€์—๋Š” ๋์ด ์—†์ง€. ๋” ๊นŠ์ด ๊ณต๋ถ€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ด๋Ÿฐ ๊ฒƒ๋“ค์„ ์‚ดํŽด๋ด:

๐Ÿ“š ํ”„๋ ˆ์ž„์›Œํฌ ํ•™์Šต

โ€ข React Router ์‹ฌํ™”

โ€ข Vue Router ๋งˆ์Šคํ„ฐ

โ€ข Next.js (React SSR)

โ€ข Nuxt.js (Vue SSR)

๐ŸŽฏ ๊ณ ๊ธ‰ ์ฃผ์ œ

โ€ข ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง

โ€ข ์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ (SSG)

โ€ข ์ฆ๋ถ„ ์ •์  ์žฌ์ƒ์„ฑ (ISR)

โ€ข ๋งˆ์ดํฌ๋กœ ํ”„๋ก ํŠธ์—”๋“œ

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™”

โ€ข ๋ฒˆ๋“ค ์ตœ์ ํ™”

โ€ข ์ด๋ฏธ์ง€ ์ตœ์ ํ™”

โ€ข ์บ์‹ฑ ์ „๋žต

โ€ข Web Vitals ๊ฐœ์„ 

๐ŸŽ“ ์ถ”์ฒœ ํ•™์Šต ๊ฒฝ๋กœ


1๋‹จ๊ณ„: ๊ธฐ์ดˆ ๋‹ค์ง€๊ธฐ

โ€ข JavaScript ES6+ ๋ฌธ๋ฒ•

โ€ข DOM ์กฐ์ž‘

โ€ข ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ

โ€ข Promise์™€ async/await


2๋‹จ๊ณ„: ๋ผ์šฐํŒ… ์ดํ•ดํ•˜๊ธฐ

โ€ข History API

โ€ข URL ํŒŒ์‹ฑ

โ€ข ์ •๊ทœํ‘œํ˜„์‹

โ€ข ์ƒํƒœ ๊ด€๋ฆฌ


3๋‹จ๊ณ„: ์‹ค์ „ ํ”„๋กœ์ ํŠธ

โ€ข ๊ฐ„๋‹จํ•œ SPA ๋งŒ๋“ค๊ธฐ

โ€ข ๋ผ์šฐํ„ฐ ์ง์ ‘ ๊ตฌํ˜„

โ€ข ํ”„๋ ˆ์ž„์›Œํฌ ์‚ฌ์šฉ

โ€ข ๋ฐฐํฌํ•˜๊ธฐ


4๋‹จ๊ณ„: ์ตœ์ ํ™”์™€ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ

โ€ข SSR/SSG ๊ตฌํ˜„

โ€ข ์„ฑ๋Šฅ ์ตœ์ ํ™”

โ€ข SEO ๊ฐœ์„ 

โ€ข ํ…Œ์ŠคํŒ…

๐Ÿ’ก ํ•™์Šต ํŒ: ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋“ค๊ณผ ์ง€์‹์„ ๊ณต์œ ํ•˜๋ฉด์„œ ๋ฐฐ์šฐ๋ฉด ํ›จ์”ฌ ๋น ๋ฅด๊ฒŒ ์„ฑ์žฅํ•  ์ˆ˜ ์žˆ์–ด. ํ˜ผ์ž ๊ณต๋ถ€ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ํ•จ๊ป˜ ํ•˜๋Š” ๊ฒŒ ๋” ์žฌ๋ฏธ์žˆ๊ณ  ํšจ๊ณผ์ ์ด๊ฑฐ๋“ ! ๐Ÿ˜Š

๐Ÿ’ฌ ๋งˆ์น˜๋ฉฐ

์™€! ์ •๋ง ๊ธด ์—ฌ์ •์ด์—ˆ์ง€? ๐Ÿ˜… JavaScript ๋ผ์šฐํŒ…๊ณผ SPA ๋„ค๋น„๊ฒŒ์ด์…˜์— ๋Œ€ํ•ด ์ •๋ง ๋งŽ์€ ๊ฑธ ๋ฐฐ์› ์–ด. ์ฒ˜์Œ์—๋Š” ๋ณต์žกํ•ด ๋ณด์˜€์ง€๋งŒ, ํ•˜๋‚˜์”ฉ ๋œฏ์–ด๋ณด๋‹ˆ๊นŒ ๊ทธ๋ ‡๊ฒŒ ์–ด๋ ต์ง€ ์•Š์•˜์ง€?


ํ•ต์‹ฌ์„ ์ •๋ฆฌํ•˜์ž๋ฉด:

๐ŸŽฏ ๊ธฐ์–ตํ•ด์•ผ ํ•  ํ•ต์‹ฌ ํฌ์ธํŠธ


1. SPA๋Š” ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ํฌ๊ฒŒ ํ–ฅ์ƒ์‹œ์ผœ - ํŽ˜์ด์ง€ ์ƒˆ๋กœ๊ณ ์นจ ์—†์ด ๋ถ€๋“œ๋Ÿฌ์šด ์ „ํ™˜


2. ๋ผ์šฐํŒ…์€ SPA์˜ ์‹ฌ์žฅ - URL ๊ด€๋ฆฌ์™€ ๋„ค๋น„๊ฒŒ์ด์…˜์˜ ํ•ต์‹ฌ


3. ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์ด ์žˆ์–ด - Hash ๊ธฐ๋ฐ˜๊ณผ History API ๊ธฐ๋ฐ˜


4. ๋ณด์•ˆ๊ณผ ์ธ์ฆ์€ ํ•„์ˆ˜ - ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„ ๋ชจ๋‘์—์„œ ์ฒดํฌ


5. ์„ฑ๋Šฅ ์ตœ์ ํ™”๊ฐ€ ์ค‘์š”ํ•ด - ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ…, ์บ์‹ฑ, ํ”„๋ฆฌํŽ˜์นญ


6. SEO๋ฅผ ์žŠ์ง€ ๋งˆ - ๋ฉ”ํƒ€ ํƒœ๊ทธ ๊ด€๋ฆฌ์™€ SSR ๊ณ ๋ ค


7. ๋ชจ๋ฐ”์ผ ์ตœ์ ํ™”๋Š” ํ•„์ˆ˜ - ํ„ฐ์น˜ ์ œ์Šค์ฒ˜์™€ ๋ฐ˜์‘ํ˜• ๋””์ž์ธ


8. ํ…Œ์ŠคํŒ…์œผ๋กœ ์•ˆ์ •์„ฑ ํ™•๋ณด - ์œ ๋‹› ํ…Œ์ŠคํŠธ์™€ E2E ํ…Œ์ŠคํŠธ

์ด์ œ ๋„ˆ๋„ ๋ฉ‹์ง„ SPA๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด! ์ฒ˜์Œ์—๋Š” ์ž‘์€ ํ”„๋กœ์ ํŠธ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ์ ์  ๋ณต์žกํ•œ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด๋‚˜๊ฐ€๋ฉด ๋ผ. ์‹ค์ˆ˜ํ•˜๋Š” ๊ฒŒ ๋‘๋ ต์ง€ ์•Š์•„๋„ ๋ผ. ์‹ค์ˆ˜๋ฅผ ํ†ตํ•ด ๋ฐฐ์šฐ๋Š” ๊ฒŒ ๊ฐ€์žฅ ๋น ๋ฅธ ๋ฐฉ๋ฒ•์ด๋‹ˆ๊นŒ! ๐Ÿ’ช


๊ทธ๋ฆฌ๊ณ  ํ˜ผ์ž ๊ณ ๋ฏผํ•˜์ง€ ๋ง๊ณ , ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋“ค๊ณผ ์†Œํ†ตํ•˜๋ฉด์„œ ๋ฐฐ์›Œ๋‚˜๊ฐ€. ์งˆ๋ฌธํ•˜๊ณ , ๋‹ต๋ณ€ํ•˜๊ณ , ์ง€์‹์„ ๋‚˜๋ˆ„๋‹ค ๋ณด๋ฉด ์–ด๋А์ƒˆ ์ „๋ฌธ๊ฐ€๊ฐ€ ๋˜์–ด ์žˆ์„ ๊ฑฐ์•ผ! ๐Ÿš€


์ž, ์ด์ œ ์ฝ”๋“œ ์—๋””ํ„ฐ๋ฅผ ์—ด๊ณ  ์ง์ ‘ ๋งŒ๋“ค์–ด๋ด! ์ฝ๊ธฐ๋งŒ ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์ง์ ‘ ์ฝ”๋”ฉํ•˜๋Š” ๊ฒŒ ๋ฐฑ ๋ฐฐ๋Š” ๋” ๋„์›€์ด ๋ผ. ํ™”์ดํŒ…! ๐Ÿ”ฅ

๐ŸŽ‰ ์—ฌ๊ธฐ๊นŒ์ง€ ์ฝ์–ด์ค˜์„œ ๊ณ ๋งˆ์›Œ!

์ด ๊ธ€์ด ๋„์›€์ด ๋๋‹ค๋ฉด ์ฃผ๋ณ€ ๊ฐœ๋ฐœ์ž ์นœ๊ตฌ๋“ค์—๊ฒŒ๋„ ๊ณต์œ ํ•ด์ค˜!

Happy Coding! ๐Ÿ’ปโœจ

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.