T
TanStack4mo ago
manual-pink

basepath issue

I am trying to deploy to github pages which introduces a mandatory repo name base path in the url. So to account for this i am setting basepath in in createRouter options and also base: in my vite.config.js. the issue im getting is that when i do this, i get a spam of errors, suggesting the app is trying to call react createRoot twice, and the entire app gets duplicated again below (as in, not rerendered twice, but i can actually see two of everything). If i remove the base path properties, then this issue stops happening. any idea how to fix?
No description
3 Replies
manual-pink
manual-pinkOP4mo ago
ok turned out to be that exporting router from main.tsx and importing it elsewhere caused react createroot to be rerun. i only needed that because i wanted a nice way in a util function to build a url. is there some way to access it wtihin a function without having to pass the router from a component that got it via useRouter?
broad-brown
broad-brown4mo ago
My understanding is, that all router logic under the hood is also using React context. This means that the router is only defined within your component structure and routes. Aka all router based functionlity needs to be called either in a loader or a component. In loader funcs, the router gets passed as an argument (so you can forward that to your util when it is called in a loader func). If you need to call your function within a component, than you can just use the useRouter hook (or one of the more specific hooks).
manual-pink
manual-pinkOP4mo ago
thanks

Did you find this page helpful?