Open LoyalEnv0y opened 3 months ago
The only solution I have found so far is to set the strict
property of the useSearch
hook to false:
import { TInstituteSearchParams} from '../../types/institutes';
const { page, pageSize, searchTerm, sortColumn, filters } = useSearch({
strict: false,
}) as TInstituteSearch;
I don't know if there is a better fix for this. From what I understand, it is caused by the nested /_authenticated/_institutes/institute
routing. When I try to specify the from
property of the useSearch
hook in a root route like /error
, it works without an error.
When using a pathless/layout route, you need to have a configuration file for that route.
Here's the fixed reproduction (note, the _auth.tsx
and _institutes.tsx
files).
https://stackblitz.com/edit/github-fyoeqy-jkyv4p?file=src%2Froutes%2Findex.tsx
Speaking with @schiller-manuel, we came to the conclusion that the router-generator
should create a virtual layout route in the generated route tree.
For consideration, if a user has a layout route identifier with no critical or non-critical configuration files, we should probably console.warn
the user that they are using the layout route setting without any actual configuration.
Thank you for your help Sean, the problem is definitely fixed on my side.
I've read the docs but I don't remember reading the layout routes requiring a config file. A warning in the console would help a lot to devs encountering the same problem in the future.
Describe the bug
I get an uncaught runtime error when I try to use the
useSearch
hook.I was trying to move my state managed filters to search parameters so it would be easier for users to share filtered contents. To do this, I followed the instractions provided on the official Tanstack-Router guide.
Here is the code I have used to create my search parameters:
Then I am simply trying to get the parameter values from the parameters. I have tried doing this in two ways:
First way:
Second way:
Both of these methods causes the Cannot read properties of undefined (reading 'routeId') error:
The only way to not get this error is to no include the
from
property in theuseSearch
hook but they I get a typescript error sayingExpected 1 arguments, but got 0.
. I don't know what causes this.Your Example Website or App
https://stackblitz.com/edit/github-fyoeqy?file=src%2Fpages%2FInstitute.tsx
Steps to Reproduce the Bug or Issue
Click on the institutes link in the navbar. In this example I get a different error which says that
Invariant failed: Could not find an active match from "/_auth/_institutes/institutes"
even though it exists on the routetree.Here is the generated routeTree.gen.ts file on my local problem:
Expected behavior
Should route to the page without causing the runtime error.
Screenshots or Videos
No response
Platform
Additional context
This is my route definitions: