T
TanStackโ€ข3y ago
correct-apricot

Have to click twice to navigate with Link

Hi all, I would like to try Tanstack routing and I followed the official sample. It works, but I have to click twice on the Link to let the page load the right content:
import React, { StrictMode } from 'react'
import ReactDOM from 'react-dom/client'
import {
Outlet,
RouterProvider,
Link,
Router,
Route,
RootRoute,
} from '@tanstack/router'
import App from './App'

// Create a root route
const rootRoute = new RootRoute({
component: Root,
})

function Root() {
return (
<>
<div>
<Link to="/">Home</Link> <Link to="/about">About</Link>
</div>
<hr />
<Outlet />
</>
)
}

// Create an index route
const indexRoute = new Route({
getParentRoute: () => rootRoute,
path: '/',
component: Index,
})

function Index() {
return (
<div>
<h3>Welcome Home!</h3>
</div>
)
}

const aboutRoute = new Route({
getParentRoute: () => rootRoute,
path: '/about',
component: About,
})

function About() {
return <App/>
}

// Create the route tree using your routes
const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])

// Create the router using your route tree
const router = new Router({ routeTree })

// Register your router for maximum type safety
declare module '@tanstack/router' {
interface Register {
router: typeof router
}
}

// Render our app!
const rootElement = document.getElementById('root')!
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement)
root.render(
<StrictMode>
<RouterProvider router={router} />
</StrictMode>,
)
}
import React, { StrictMode } from 'react'
import ReactDOM from 'react-dom/client'
import {
Outlet,
RouterProvider,
Link,
Router,
Route,
RootRoute,
} from '@tanstack/router'
import App from './App'

// Create a root route
const rootRoute = new RootRoute({
component: Root,
})

function Root() {
return (
<>
<div>
<Link to="/">Home</Link> <Link to="/about">About</Link>
</div>
<hr />
<Outlet />
</>
)
}

// Create an index route
const indexRoute = new Route({
getParentRoute: () => rootRoute,
path: '/',
component: Index,
})

function Index() {
return (
<div>
<h3>Welcome Home!</h3>
</div>
)
}

const aboutRoute = new Route({
getParentRoute: () => rootRoute,
path: '/about',
component: About,
})

function About() {
return <App/>
}

// Create the route tree using your routes
const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])

// Create the router using your route tree
const router = new Router({ routeTree })

// Register your router for maximum type safety
declare module '@tanstack/router' {
interface Register {
router: typeof router
}
}

// Render our app!
const rootElement = document.getElementById('root')!
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement)
root.render(
<StrictMode>
<RouterProvider router={router} />
</StrictMode>,
)
}
18 Replies
dependent-tan
dependent-tanโ€ข3y ago
@SpiraBlitzer yep, known issue: https://github.com/TanStack/router/issues/597
GitHub
Beta.87 Link Path Changes but Page Content Fails to Load ยท Issue #5...
Describe the bug The bug is causing a problem where clicking on a link does not load the content of the requested page, even though the link path changes correctly. Your Example Website or App http...
correct-apricot
correct-apricotOPโ€ข3y ago
Sorry, didn't see it, thanks!
dependent-tan
dependent-tanโ€ข3y ago
No problem. Yeah, I'd expect the be the title of the issue to be like the title of your question. Glad to help ๐Ÿ˜„
generous-apricot
generous-apricotโ€ข3y ago
Sorry, I didn't went with a good title, was tired and wrote in hurry.
exotic-emerald
exotic-emeraldโ€ข3y ago
And I thought I'm insane! xD yes it is still an issue
generous-apricot
generous-apricotโ€ข3y ago
it wasn't fixed in latest beta but if you want to use router use beta.86
flat-fuchsia
flat-fuchsiaโ€ข3y ago
Okay glad this was reported. I searched "click twice" and couldn't find a github issue related to that.
passive-yellow
passive-yellowโ€ข3y ago
Is beta.86 working for yall? I have the same issue with beta 86
generous-apricot
generous-apricotโ€ข3y ago
yeah i have used beta .86 and it worked fine if you want an example i got a repo you can use to test it
passive-yellow
passive-yellowโ€ข3y ago
That'd be great if that's ok :D, thanks in advance btw
generous-apricot
generous-apricotโ€ข3y ago
GitHub
GitHub - bachiitter/quirk: An opinionated open-source template for ...
An opinionated open-source template for building full-stack web apps using React and Cloudflare Pages/Functions. - GitHub - bachiitter/quirk: An opinionated open-source template for building full-s...
generous-apricot
generous-apricotโ€ข3y ago
you will have to remove auth stuff from dashboard layout
passive-yellow
passive-yellowโ€ข3y ago
Oh it was due to having dependency of "@tanstack/router": "^0.0.1-beta.86", instead of "@tanstack/router": "0.0.1-beta.86", ๐Ÿ˜… sorry about that
generous-apricot
generous-apricotโ€ข3y ago
๐Ÿ˜… i have no idea ๐Ÿคท๐Ÿป and don't think it matters
passive-yellow
passive-yellowโ€ข3y ago
Hahah, I mean it's just the caret ^ for versioning in the package json, so it used beta 89 instead of 86
generous-apricot
generous-apricotโ€ข3y ago
oh i didn't knew about that
passive-yellow
passive-yellowโ€ข3y ago
Stack Overflow
What's the difference between tilde(~) and caret(^) in package.json?
After I upgraded to the latest stable node and npm, I tried npm install moment --save. It saves the entry in the package.json with the caret ^ prefix. Previously, it was a tilde ~ prefix. Why are ...
generous-apricot
generous-apricotโ€ข3y ago
tysm

Did you find this page helpful?