Keeping the sidebar panel expanded on a redirect
up vote
0
down vote
favorite
I have expansion panels in my sidenav and I'm keeping track of their open state and setting it. So as a different panel is opened, the state changes to reflect the panel that is open. Within my panel I have list items that on click redirect to another route. My problem is I want to keep the panel where the list item clicked open on the redirect. On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed. The list has an on click that does a react Redirect to the path.
javascript reactjs material-ui
add a comment |
up vote
0
down vote
favorite
I have expansion panels in my sidenav and I'm keeping track of their open state and setting it. So as a different panel is opened, the state changes to reflect the panel that is open. Within my panel I have list items that on click redirect to another route. My problem is I want to keep the panel where the list item clicked open on the redirect. On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed. The list has an on click that does a react Redirect to the path.
javascript reactjs material-ui
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have expansion panels in my sidenav and I'm keeping track of their open state and setting it. So as a different panel is opened, the state changes to reflect the panel that is open. Within my panel I have list items that on click redirect to another route. My problem is I want to keep the panel where the list item clicked open on the redirect. On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed. The list has an on click that does a react Redirect to the path.
javascript reactjs material-ui
I have expansion panels in my sidenav and I'm keeping track of their open state and setting it. So as a different panel is opened, the state changes to reflect the panel that is open. Within my panel I have list items that on click redirect to another route. My problem is I want to keep the panel where the list item clicked open on the redirect. On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed. The list has an on click that does a react Redirect to the path.
javascript reactjs material-ui
javascript reactjs material-ui
asked Nov 19 at 21:16
AnneJoday
246
246
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
Answering your question without regard to React:
Store the panel state in .localStorage
upon state change:
localStorage.setItem('panelState',JSON.stringify(myStateObj));
Upon .DOMContentLoaded
retrieve and restore the state:
restoreState(JSON.parse(localStorage.getItem('panelState')));
If you are using React, one has to wonder why you are not using it as a SPA, but that is for another Q&A I suppose
Do you have an example of how to do this? I know how to store the panel state in .localstorage. I don't understand the .DomContentLoaded and where I'd put that. Where does that code belong. In the component did mount of my sidenav class? I'm kind of confused about that. Also, it is a single page app. The routes are programatically created through the Gatsby API.
– AnneJoday
Nov 19 at 22:05
My answer is moot if it is a SPA. This statement is confusing: On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed.. You should be maintaining state in a component.
– Randy Casburn
Nov 19 at 22:38
But I am, which is why I'm confused as to why when the redirect happens the sidenav collapses.
– AnneJoday
Nov 20 at 0:23
add a comment |
up vote
0
down vote
Try using a layout with a left and right sections. Keep the state in main component and when something is clicked, update the right side that is the content section. That should do the trick without any hassle
add a comment |
up vote
0
down vote
I would say use redux or some state management lib if you have installed already its best.
another best way would be using a layout page in your main file i.e. app.js and load your routers in layout body and your layout state management will be in state management.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382759%2fkeeping-the-sidebar-panel-expanded-on-a-redirect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Answering your question without regard to React:
Store the panel state in .localStorage
upon state change:
localStorage.setItem('panelState',JSON.stringify(myStateObj));
Upon .DOMContentLoaded
retrieve and restore the state:
restoreState(JSON.parse(localStorage.getItem('panelState')));
If you are using React, one has to wonder why you are not using it as a SPA, but that is for another Q&A I suppose
Do you have an example of how to do this? I know how to store the panel state in .localstorage. I don't understand the .DomContentLoaded and where I'd put that. Where does that code belong. In the component did mount of my sidenav class? I'm kind of confused about that. Also, it is a single page app. The routes are programatically created through the Gatsby API.
– AnneJoday
Nov 19 at 22:05
My answer is moot if it is a SPA. This statement is confusing: On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed.. You should be maintaining state in a component.
– Randy Casburn
Nov 19 at 22:38
But I am, which is why I'm confused as to why when the redirect happens the sidenav collapses.
– AnneJoday
Nov 20 at 0:23
add a comment |
up vote
0
down vote
Answering your question without regard to React:
Store the panel state in .localStorage
upon state change:
localStorage.setItem('panelState',JSON.stringify(myStateObj));
Upon .DOMContentLoaded
retrieve and restore the state:
restoreState(JSON.parse(localStorage.getItem('panelState')));
If you are using React, one has to wonder why you are not using it as a SPA, but that is for another Q&A I suppose
Do you have an example of how to do this? I know how to store the panel state in .localstorage. I don't understand the .DomContentLoaded and where I'd put that. Where does that code belong. In the component did mount of my sidenav class? I'm kind of confused about that. Also, it is a single page app. The routes are programatically created through the Gatsby API.
– AnneJoday
Nov 19 at 22:05
My answer is moot if it is a SPA. This statement is confusing: On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed.. You should be maintaining state in a component.
– Randy Casburn
Nov 19 at 22:38
But I am, which is why I'm confused as to why when the redirect happens the sidenav collapses.
– AnneJoday
Nov 20 at 0:23
add a comment |
up vote
0
down vote
up vote
0
down vote
Answering your question without regard to React:
Store the panel state in .localStorage
upon state change:
localStorage.setItem('panelState',JSON.stringify(myStateObj));
Upon .DOMContentLoaded
retrieve and restore the state:
restoreState(JSON.parse(localStorage.getItem('panelState')));
If you are using React, one has to wonder why you are not using it as a SPA, but that is for another Q&A I suppose
Answering your question without regard to React:
Store the panel state in .localStorage
upon state change:
localStorage.setItem('panelState',JSON.stringify(myStateObj));
Upon .DOMContentLoaded
retrieve and restore the state:
restoreState(JSON.parse(localStorage.getItem('panelState')));
If you are using React, one has to wonder why you are not using it as a SPA, but that is for another Q&A I suppose
answered Nov 19 at 21:21
Randy Casburn
4,2091318
4,2091318
Do you have an example of how to do this? I know how to store the panel state in .localstorage. I don't understand the .DomContentLoaded and where I'd put that. Where does that code belong. In the component did mount of my sidenav class? I'm kind of confused about that. Also, it is a single page app. The routes are programatically created through the Gatsby API.
– AnneJoday
Nov 19 at 22:05
My answer is moot if it is a SPA. This statement is confusing: On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed.. You should be maintaining state in a component.
– Randy Casburn
Nov 19 at 22:38
But I am, which is why I'm confused as to why when the redirect happens the sidenav collapses.
– AnneJoday
Nov 20 at 0:23
add a comment |
Do you have an example of how to do this? I know how to store the panel state in .localstorage. I don't understand the .DomContentLoaded and where I'd put that. Where does that code belong. In the component did mount of my sidenav class? I'm kind of confused about that. Also, it is a single page app. The routes are programatically created through the Gatsby API.
– AnneJoday
Nov 19 at 22:05
My answer is moot if it is a SPA. This statement is confusing: On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed.. You should be maintaining state in a component.
– Randy Casburn
Nov 19 at 22:38
But I am, which is why I'm confused as to why when the redirect happens the sidenav collapses.
– AnneJoday
Nov 20 at 0:23
Do you have an example of how to do this? I know how to store the panel state in .localstorage. I don't understand the .DomContentLoaded and where I'd put that. Where does that code belong. In the component did mount of my sidenav class? I'm kind of confused about that. Also, it is a single page app. The routes are programatically created through the Gatsby API.
– AnneJoday
Nov 19 at 22:05
Do you have an example of how to do this? I know how to store the panel state in .localstorage. I don't understand the .DomContentLoaded and where I'd put that. Where does that code belong. In the component did mount of my sidenav class? I'm kind of confused about that. Also, it is a single page app. The routes are programatically created through the Gatsby API.
– AnneJoday
Nov 19 at 22:05
My answer is moot if it is a SPA. This statement is confusing: On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed.. You should be maintaining state in a component.
– Randy Casburn
Nov 19 at 22:38
My answer is moot if it is a SPA. This statement is confusing: On the redirect to the list item route, a refresh happens and the sidenav goes back to its original state which is obviously expansion panels collapsed.. You should be maintaining state in a component.
– Randy Casburn
Nov 19 at 22:38
But I am, which is why I'm confused as to why when the redirect happens the sidenav collapses.
– AnneJoday
Nov 20 at 0:23
But I am, which is why I'm confused as to why when the redirect happens the sidenav collapses.
– AnneJoday
Nov 20 at 0:23
add a comment |
up vote
0
down vote
Try using a layout with a left and right sections. Keep the state in main component and when something is clicked, update the right side that is the content section. That should do the trick without any hassle
add a comment |
up vote
0
down vote
Try using a layout with a left and right sections. Keep the state in main component and when something is clicked, update the right side that is the content section. That should do the trick without any hassle
add a comment |
up vote
0
down vote
up vote
0
down vote
Try using a layout with a left and right sections. Keep the state in main component and when something is clicked, update the right side that is the content section. That should do the trick without any hassle
Try using a layout with a left and right sections. Keep the state in main component and when something is clicked, update the right side that is the content section. That should do the trick without any hassle
answered Nov 19 at 21:41
klvenky
73110
73110
add a comment |
add a comment |
up vote
0
down vote
I would say use redux or some state management lib if you have installed already its best.
another best way would be using a layout page in your main file i.e. app.js and load your routers in layout body and your layout state management will be in state management.
add a comment |
up vote
0
down vote
I would say use redux or some state management lib if you have installed already its best.
another best way would be using a layout page in your main file i.e. app.js and load your routers in layout body and your layout state management will be in state management.
add a comment |
up vote
0
down vote
up vote
0
down vote
I would say use redux or some state management lib if you have installed already its best.
another best way would be using a layout page in your main file i.e. app.js and load your routers in layout body and your layout state management will be in state management.
I would say use redux or some state management lib if you have installed already its best.
another best way would be using a layout page in your main file i.e. app.js and load your routers in layout body and your layout state management will be in state management.
answered Nov 19 at 22:03
m-farhan
1,084810
1,084810
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382759%2fkeeping-the-sidebar-panel-expanded-on-a-redirect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown