tip-archive icon indicating copy to clipboard operation
tip-archive copied to clipboard

vue-router issue

Open jbee37142 opened this issue 6 years ago โ€ข 0 comments

Description

/foo/bar์™€ ๊ฐ™์ด second level path๋กœ directly ์ ‘๊ทผ์„ ์‹œ๋„ํ•  ๋•Œ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

Uncaught SyntaxError: Unexpected token <

vue-router ์ด์Šˆ์ธ์ค„ ์•Œ์•˜๋Š”๋ฐ, ๋””๋ฒ„๊น… ๊ฒฐ๊ณผ ์ •๋ง ์•„๋ฌด ์ด์ƒ์ด ์—†์—ˆ๋‹ค. ์ด์œ ๋Š” app.js path๊ฐ€ ์ž˜๋ชป๋˜์–ด์žˆ์—ˆ๋‹ค.

  • (X) app.js
  • (O) /app.js

vue.config.js์—์„œ publicPath๊ฐ’์„ ์„ค์ •ํ•ด์ค„ ๋•Œ, '' ๊ฐ’์œผ๋กœ ์„ค์ •ํ•ด๋’€๋”๋‹ˆ

<script src="app.js"></script>

์ด๋Ÿฐ ์‹์œผ๋กœ ํ˜ธ์ถœํ•˜๊ณ  ์žˆ์—ˆ๋‹ค.

Solve

vue.config.js์—์„œ publicPath๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค.

publicPath

  • index.html์—์„œ ์ฐธ์กฐํ•˜๊ฒŒ ๋˜๋Š” base url์„ ์˜๋ฏธํ•œ๋‹ค.
  • ์ด์ „ ๋ฒ„์ „์—์„œ๋Š” baseUrl๋กœ ์‚ฌ์šฉ๋˜์—ˆ๋‹ค.
  • webpack์˜ publicPath์™€ ๋™์ผํ•˜๋‹ค.

Reference

  • https://stackoverflow.com/questions/49276879/second-level-vue-route-throws-error-when-accessed-directly

jbee37142 avatar Feb 20 '19 07:02 jbee37142