Skip to content

In Weex, router must push('/') to make <router-view> avaliable #1139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iNahooNya opened this issue Feb 6, 2017 · 1 comment
Closed

In Weex, router must push('/') to make <router-view> avaliable #1139

iNahooNya opened this issue Feb 6, 2017 · 1 comment

Comments

@iNahooNya
Copy link

iNahooNya commented Feb 6, 2017

####In weex porject.
Router must router.push('/') to make <router-view> render corresponding component in ios.
It's a bug or a feature?


Code

In app.js

import my from './src/views/my.vue';
const router = new Router({
    routes: [
        {path: '/', component: my}
    ]
});

In main-view template:

<template>
    <div class="root-body">
        <text class="msg">router:{{path}}</text>
        <router-view></router-view>
    </div>
</template>

In main-view contructor Object:

       //...
       computed: {
            path(){
                return this.$route.path;
            },
        },
        //...

then I try this demo in my ios10.2 phone, <text> show me router : /
but <router-view> won't render corresponding component.
unless I add router.push('/'); in the end of app.js.

Like this

import my from './src/views/my.vue';
const router = new Router({
    routes: [
        {path: '/', component: my}
    ]
});
router.push('/');

it works.


Maybe useful

"dependencies": {
    "vue": "^2.1.8",
    "vue-router": "^2.1.1",
    "vuex": "^2.1.1",
    "vuex-router-sync": "^4.0.1",
    "weex-vue-render": "^0.1.4"
  },
  "devDependencies": {
    "babel-core": "^6.20.0",
    "babel-loader": "^6.2.9",
    "babel-preset-es2015": "^6.18.0",
    "css-loader": "^0.26.1",
    "less-loader": "^2.2.3",
    "serve": "^1.4.0",
    "vue-loader": "^10.0.2",
    "vue-template-compiler": "^2.1.8",
    "webpack": "^1.14.0",
    "weex-devtool": "^0.2.64",
    "weex-loader": "^0.4.1",
    "weex-vue-loader": "^0.2.5"
  }
@fnlctrl
Copy link
Member

fnlctrl commented Feb 6, 2017

This is expected since the router is working in abstract mode in non-browser environments (node, weex, etc). In abstract mode, the router won't automatically navigate to '/' and it is required that you use router.push() to explicitly set a initial view.

Quote from Evan (#729)

This is intended - in the browser, the user may visit the non-root URL on initial load, so the root view may not get rendered at all. In abstract mode, when the application boots it will be in a "nowhere" state until you explicitly tell the router where it is. This gives you a chance to render a non-root URL as your initial view, instead of rendering the root view and then triggering a navigation + re-render.

@fnlctrl fnlctrl closed this as completed Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants