Skip to content
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

How to use nested routing in a code based manner #2835

Closed
LinHanlove opened this issue Nov 23, 2024 · 2 comments
Closed

How to use nested routing in a code based manner #2835

LinHanlove opened this issue Nov 23, 2024 · 2 comments

Comments

@LinHanlove
Copy link

Which project does this relate to?

Router

Describe the bug

首先我用的是基于代码的路由,我创建了 '父组件' -- 【Home】,他可以正常跳转,我也创建了基于home的子组件 -- 【homeChild】,所有他们的路径如下

  • /home --- 跳转到Home页面
  • /home/child --- 跳转到Home下的HomdChild
    但是,这是错误的,跳转不过去,Not Found

Your Example Website or App

https://stackblitz.com/edit/github-gcuesq?file=src%2Fhome%2Findex.tsx

Steps to Reproduce the Bug or Issue

  • /home --- 跳转到Home页面
  • /home/child --- 跳转到Home下的HomdChild
    但是,这是错误的,跳转不过去,Not Found

Expected behavior

The expected result should be/home navigating to the Home page,/home/child navigating to [HomeChild] under [Home]

Screenshots or Videos

follows:
Image
Image
Image

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

@schiller-manuel
Copy link
Contributor

path of child was wrong

const homeChildRoute = createRoute({
  getParentRoute: () => homeRoute,
  path: 'child',
}).lazy(() => import('./home/homeChild').then((d) => d.HomeChild));

have a look at https://stackblitz.com/edit/github-gcuesq-ch7m7n?file=src%2Fmain.tsx,src%2Fabout.tsx

Image

@LinHanlove
Copy link
Author

孩子的道路是错误的

const homeChildRoute = createRoute({
getParentRoute: () => homeRoute,
path: 'child',
}).lazy(() => import('./home/homeChild').then((d) => d.HomeChild));
看看https://stackblitz.com/edit/github-gcuesq-ch7m7n?file=src%2Fmain.tsx,src%2Fabout.tsx

Image

I have a layout component where the outlet controls the global layout rendering. However, if I write it this way, I have to write an outlet on the home page as well. But this way, when I navigate to/home/child, home will appear and the content of the page will also be rendered. However, if it is like other frameworks such as vureroute, this situation will not occur. This is very confusing. I just want to use a globally unified outlet, and when I navigate to home/child, please do not display the content of the home parent component. How can I do this

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