Replies: 2 comments
-
Following up, I was able to reproduced the expected behavior using client-only paths. Notice how on route change, the parent component does not get unmounted since the content does not change Kapture.2021-02-21.at.17.48.44.mp4// src/pages/[...].js
import {Link} from 'gatsby';
import React from 'react';
import {Location, Router} from '@reach/router';
export default class App extends React.Component {
componentWillUnmount() {
window.alert('componentWillUnmount App');
}
render() {
return (
<div>
<Location>
{({location}) => (
<Router location={location}>
<Parent default path="parent">
<Foo path="foo" />
<Bar path="bar" />
</Parent>
</Router>
)}
</Location>
</div>
);
}
}
class Parent extends React.Component {
componentWillUnmount() {
window.alert('componentWillUnmount Parent');
}
render() {
return (
<div>
<div style={{display: 'flex'}}>
<div style={{marginRight: '8px'}}>CURRENT: parent</div>
{this.props.children}
</div>
<div>
go to <Link to="/parent">/parent</Link>
</div>
<div>
go to <Link to="/parent/foo">/parent/foo</Link>
</div>
<div>
go to <Link to="/parent/bar">/parent/bar</Link>
</div>
</div>
);
}
}
class Foo extends React.Component {
componentWillUnmount() {
window.alert('componentWillUnmount foo');
}
render() {
return <div> foo</div>;
}
}
class Bar extends React.Component {
componentWillUnmount() {
window.alert('componentWillUnmount bar');
}
render() {
return <div> bar</div>;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi! As laid out in the linked issue and the original one (#6127) this is currently working as expected. Please open a feature request for this: https://github.com/gatsbyjs/gatsby/discussions/categories/ideas-feature-requests Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Routes sharing the same component will fully unmount and remount on transition (NOTE: This is not the same as sharing the same
Layout
)Steps to reproduce
gatsby-node
, create two pages using the samecomponent
/foo
to/bar
or/bar
to/foo
will cause the page component to unmount and remount even though the exact same content is being renderedReproduction case: https://codesandbox.io/s/vibrant-morse-vkdkb?file=/src/components/foobar.js
Expected result
The page component should not unmount and remount since they are exactly the same
Actual result
The page component is unmounted and remounted even though the component is exactly the same
Environment
Related tickets / issues
Beta Was this translation helpful? Give feedback.
All reactions