tip-archive
tip-archive copied to clipboard
vue-router issue
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