vue3-tsx's People
Forkers
zifeiyu-12321vue3-tsx's Issues
关于子路由下的router-view的问题
需求是:
页面共有一个顶部导航,所以实现了一个layout的组建
// layout.jsx
import { defineComponent } from "vue";
import AppMain from "./AppMain";
import Navbar from "./Navbar";
export default defineComponent({
name: 'Layout',
setup(props, ctx) {
return () => (
<div>
<Navbar />
<AppMain />
</div>
)
}
})
路由设置为
import { createRouter, createWebHashHistory } from "vue-router";
import Layout from "../layout";
const routes = [
{
path: '/',
redirect: '/home',
},
{
path: '/home',
component: Layout,
children: [
{
path: 'index',
name: 'Home',
component: () => import('../views/home')
}
]
},
{
path: '/login',
name: 'Login',
component: () => import('../views/login')
}
]
const router = createRouter({
history: createWebHashHistory(),
routes: routes,
})
router.beforeEach((to, from) => {
// 返回 false 则取消导航
if(to.path === '/login') {
// 登录页面不做限制
return true
} else {
// 判断缓存中是否有 token 如果没有 则跳转到登录页面
if(localStorage.getItem('token')) {
return true
} else {
router.push('/login')
return false
}
}
})
export default router
关键问题是这里的AppMain中的router-view用jsx怎么写,渲染有问题
import { defineComponent, KeepAlive, Transition } from "vue";
import { RouterView } from "vue-router";
export default defineComponent({
name: 'AppMain',
setup(props, ctx) {
return () => (
<div class="app-main">
<p>down is router view</p>
<RouterView>
{
({Component}) => (
<KeepAlive>
<Component />
</KeepAlive>
)
}
</RouterView>
</div>
)
}
})
router-view中的内容渲染不出来
[Vue warn]: Invalid vnode type when creating vnode: undefined.
at <RouterView>
at <AppMain>
at <Layout onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > >
at <RouterView>
at <App>
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.