Go Back to Previous Page
You can use a link to invoke history.go(-1)
in Javascript, which is essentially equivalent to clicking the Back button. Ideally, however, it'd be better to just create a link back to the URL from whence the user was posted to the form - that way the proper "flow" of history is preserved and the user doesn't wonder why they have something to click "Forward" to which is actually just submitting the form again.
How to go back to previous page in Next.js using `next/router`?
<Link>
can't go outside of your app. (but router.back()
can)
You can't use router.back()
directly in the code, you need to do something like :
<img onClick={() => router.back()} src="icon.svg" />
<Link>
does not have onClick property.
import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
return (
<button type="button" onClick={() => router.back()}>
Click here to go back
</button>
)
}
Source of info here
Return to previous window on click of 'Go to previous page' link
Use window.close() to close an opened tab.
Go back to previous page regardless of changes in query string
Instead of history.back()
, which goes back only by one, you could do window.location.replace(window.location.host)
, which loads the root page.
To get more info on window.location
: https://developer.mozilla.org/en-US/docs/Web/API/Window/location
Edit:
If you want to ignore URL parameters, you need to change how you go to another page.
Instead of window.history.pushState(...)
, you should use window.history.replaceState(...)
, when the navigation should be ignored on a back click.
Here more to read on that topic: What is the trade off between history push and replace?
Return To Previous Page - Laravel 8 Project
This was very useful Laravel Session
public function index(Request $request){
$categories = Category::latest()->paginate(5);
//the following snippet creates persistent session variables
$request->session()->put('page',$categories->currentPage());
return view('orders.view',compact('orders'));
}
Also changed the View Categories
button from this:
<a href="{{ url()->previous() }}" class="btn btn-primary"><i class="material-icons">arrow_back</i> View Categories</a>
To this:
<a href="{{ Session::has('page') ? '/categories?page=' . Session::get('page') : '/categories' }}" class="btn btn-primary"><i class="material-icons">arrow_back</i> View Categories</a>
This button first tests if $_SESSION['page']
was set and if so when clicked it assigned the last known value to ?page=
, as extra precaution, if for whatever reason the session value was not found the button will just redirect back to category.view
which is the categories landing page.
This is exactly what I wanted to achieve and I was surprised to find that nothing native or built-in method exists because I've checked most public forums and re-checked the Laravel Doc and found nothing to what I'm looking for.
Maybe the question was just not clear enough but I am sure I've provided enough material to give a clear picture of what I wanted to achieve.
Related Topics
Update Without Touching Timestamps (Laravel)
How to Create Custom Seo-Friendly Urls in Opencart
Accessing Main Picture of Wikipedia Page by API
Hunting Cheaters in a Voting Competition
Proper Session Hijacking Prevention in PHP
Simple Way to Read Single Record from MySQL
Storing Datetime as Utc in PHP/Mysql
Convert Lat/Longs to X/Y Co-Ordinates
Cron Command to Run Url Address Every 5 Minutes
How to Inject a Repository into a Service in Symfony
How Would I Implement a Simple Site Search with PHP and MySQL
Explain $Ci =& Get_Instance();
How to Access Service Container in Symfony2 Global Helper Function (Service)
Determine If Business Is Open/Closed Based on Business Hours