programing

Vue 라우터 및 Cordova(Vue.js)

minecode 2022. 8. 25. 23:32
반응형

Vue 라우터 및 Cordova(Vue.js)

편집

라우터가 이력 모드로 되어 있는 것과 관계가 있는 것을 알게 되었습니다.'mode': 'history',router.display에서 모든 것이 다시 작동합니다.다른 사람들이 같은 문제를 겪거나 누군가 해명을 해줄 수 있다면 이곳을 떠나는 것...

원래의

vue v2를 vue-router 및 cordova와 함께 사용할 수 없습니다(즉, vue v2를 빌드하는 경우)cordova/wwwcordova 작업을 index.files에서 수행하도록 합니다).이전에는 vue와 vue-router v1을 사용할 수 있었습니다.vue v2에서도 사용할 수 있지만 vue-router를 사용하지 않습니다.

확실히 말하면, 앱은 사용할 때 동작합니다.npm run dev빌딩을 열 때는 그렇지 않습니다.index.html.

이것은 라우터가 다음 루트를 찾는 것과 관련이 있는 것 같습니다./근데 보니까index.html?

여기 문제를 재현할 수 있는 보고서가 있습니다.

다음은 관련 코드입니다.

main.filename:

import Vue from 'vue';
import App from './App.vue';
import router from './router/router.js';
    
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  // replace the content of <div id="app"></div> with App
  render: h => h(App),
});

app.vue:

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <router-view></router-view>
  </div>
</template>
    
<script>
import Hello from './components/Hello';
    
export default {
  name: 'app',
  components: {
    Hello,
  }
}
</script>
    
<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

/syslog/syslog.syslog:

import Vue from 'vue';
import Router from 'vue-router';
    
Vue.use(Router);
    
import Hello from '../components/Hello';
    
export default new Router({
  'mode': 'history',
  scrollBehavior: () => ({ y: 0 }),
  'routes': [
    {
      'path': '/',
      'component': Hello,
    }
  ]
})

config/index.disc:

// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path');
    
module.exports = {
  build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../../cordova/www/index.html'),
    assetsRoot: path.resolve(__dirname, '../../cordova/www'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '',
    productionSourceMap: true,
    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],
  },
  dev: {
    env: require('./dev.env'),
    port: 8080,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},
    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false,
  }
}

디스크("file://")에서 파일을 로드하고 있을 때 "file://"에서 파일을 로드하면 브라우저 기록 API 푸시 상태가 작동하지 않습니다.라우터에서 "mode: history"를 삭제하면 동작합니다.이는 기본적으로 해시를 사용하기 때문입니다.

빌드 설정:assetsPublicPath: 'file:///android_asset/www/'

index.module을 변경해야 합니다. assetsPublicPath: '/'로.assetsPublicPath: './'

더하다<base href='./'>index.display 헤드의 요소.빌드 구성index.js세트assetsPublicPath: ''.

다른 홈 라우터를 추가해야 한다는 것을 알고 빈 문자열에서 변경했습니다.''로.'/index.html'

베이스 변경

<base href='./'>

Yanis가 말한 대로 라우터에서 이력을 삭제합니다.

언급URL : https://stackoverflow.com/questions/40899826/vue-router-and-cordova-vue-js

반응형