반응형
루트를 다른 파일로 분할
나는 꽤 큰 Vue 앱을 개발 중인데, 나는 이제 모든 경로를 한 페이지에 써야 한다.router/index.js
좋아하거나 유지하기에 너무 길어지고 있습니다.그index.js
페이지는...와 같은 문장으로 가득 차 있다.
import This from '../components/This'
import That from '../components/That'
import ThatOther from '../components/ThatOther'
import ThatOtherOne from '../components/ThatOtherOne'
// and so on and so on...then at the bottom
var router = new Router({
routes: [
{
path: '/this',
name: 'this',
component: This
},
{
path: '/that',
name: 'that',
component: That
},
// and so on...so many lines of similar and "repetitive" code
내 앱은 "모듈"로 그룹화될 수 있기 때문에 루트를 다른 파일로 분할할 수 있는 방법이 있습니까?import
스테이트먼트와 라우터 엔트리)의 유사점router/this.js
,router/that.js...', then add them to the main route page,
router/index.displaces'?
개별 파일:
import This from '../components/This'
import That from '../components/That'
import ThatOther from '../components/ThatOther'
import ThatOtherOne from '../components/ThatOtherOne'
export default [
{
path: '/this',
name: 'this',
component: This
},
{
path: '/that',
name: 'that',
component: That
},
]
루트 파일에서 외부 루트를 Import하고 확산 oeprator를 사용합니다.
import externalRoutesOne from './externalRoutesOne'
import externalRoutesTwo from './externalRoutesTwo'
var router = new Router({
routes: [
...externalRoutesOne,
...externalRoutesTwo
]
주의:
...
operator는 루트를 정의할 때 필요합니다.
언급URL : https://stackoverflow.com/questions/48264980/splitting-routes-into-separate-files
반응형
'sourcecode' 카테고리의 다른 글
OpenCV(Hough 변환 또는 기타 기능에 기반)를 사용한 견고한(색상과 크기 불변) 원 검출 쓰기 (0) | 2022.08.09 |
---|---|
포인터 감산 혼란 (0) | 2022.08.09 |
vue 2에서 클릭 핸들의 하위 항목 전파 사용 안 함 (0) | 2022.08.08 |
vuex 계산 속성이 무효가 아님 (0) | 2022.08.08 |
VuexFire 돌연변이 (0) | 2022.08.08 |