Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back-button style go back #3

Open
peterbe opened this issue Oct 3, 2016 · 3 comments
Open

Back-button style go back #3

peterbe opened this issue Oct 3, 2016 · 3 comments

Comments

@peterbe
Copy link

peterbe commented Oct 3, 2016

There are times when, in one component, I know for certainty that the user came from another component. And in the component they're in now I want to have a <a>Go back</a> link.
But I want to make the HTML be right-clickable.

This sort of works:

/* This is in the search result component, links back to the search resultS */
<Link view={views.search} params={{q: store.search_term_used}} store={store}>Go Back</Link>

It gets rendered out to:

<a href="/search/Search+Term+Used">Go Back</a>

But when you click that, it loads the page as a "new page" (not like a brand new browser request, it still has the onClick from mobx-router) and doesn't remember where you have scrolled down to.

If instead, I click the browser back button, it all looks the same except my browser knows how far down I was scrolled.

This sort of works:

/* This is in the search result component, links back to the search resultS */
<a href="#" onClick={(e) => this.goBack(e)}>Go Back</a>

And in that handler I can call regular history.back().

However, I now lack the nice href="..." that would make that Go Back link right-clickable.

I tried this:

/* This is in the search result component, links back to the search resultS */
<Link view={views.search} params={{q: store.search_term_used}} store={store}
  onClick={this.goBack}>Go Back</Link>

but it doesn't trigger "my" onclick but instead that of mobx-router.

Another, less desirable option is to do this:

/* This is in the search result component, links back to the search resultS */
let routeUrl = `/search/${store.search_term_used}`
<a href={routeUrl) onClick={(e) => this.goBack(e)}>Go Back</a>

...but I'd love to use something out of mobx-router to get that URL instead of having to create it as a string myself.

@kitze
Copy link
Owner

kitze commented Oct 4, 2016

Yeah, the component doesn't support a custom onClick handler because that didn't make sense to me. I understand the problem that you have thanks to your detailed explanation!

If I keep "previousView" in the router store, this would be really easy to solve. I can add a "goBack={true}" prop to the component that will always take you back to the view that you came from.

Would this solve your issue?

@peterbe
Copy link
Author

peterbe commented Oct 4, 2016

If I keep "previousView" in the router store, this would be really easy to solve. I can add a "goBack={true}" prop to the component that will always take you back to the view that you came from.

Yes please!

@kitze
Copy link
Owner

kitze commented Nov 4, 2016

@peterbe I'll tackle this tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants