-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
useRoute() return value will delay a moment #533
Comments
//main.js
import { createApp } from "vue";
import App from "./App.vue";
import { createRouter, createWebHashHistory } from "vue-router";
const Home = { template: "<div>Home</div>" };
const About = { template: "<div>About</div>" };
const routes = [
{ path: "/", name: "Home", component: Home },
{ path: "/about", name: "About", component: About }
];
const router = createRouter({
history: createWebHashHistory(),
routes
});
createApp(App).use(router).mount("#app"); <!-- App.vue -- >
<template>
<router-view />
</template>
<script>
import { onMounted } from 'vue'
import { useRoute } from 'vue-router'
export default {
name: "App",
setup() {
const route = useRoute()
onMounted(() => {
console.log(1, route.name) // just output undefined
setTimeout(() => console.log(2, route.name), 1000) // 'Home'!
})
},
};
</script>
<style>
</style> |
I've resolved this. ref: https://next.router.vuejs.org/api/#hasroute // add this snippet in you main.js or main.ts
router.isReady().then(() => {
app.mount('#app')
}) |
还有其他解决方案吗 |
router.isReady().then(() => doSomeThing() ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version
4.0.0-beta.13
Reproduction link
https://codesandbox.io/s/awesome-framework-yifz2?file=/src/App.vue
Steps to reproduce
What is expected?
// 1. "Home"
// 2. "Home"
What is actually happening?
// 1. undefined
// 2. "Home"
I have 'RTMD', but still don't know why this happend.
The text was updated successfully, but these errors were encountered: