Comments (2)
With @reinink's help, I solved this by using the CSRF token stored as a cookie instead of manually adding it to my forms.
Laravel stores an XSRF-TOKEN
cookie on responses: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php#L77
Axios reads the cookie and adds it to requests: https://github.com/axios/axios/blob/b4c5d35d2875191dfa8c3919d4227dce8e2ad23f/lib/defaults.js#L74
Submitting a form returns a response, so the cookie gets updated every time.
Since this solves my problem, I'm going to close this issue. If anyone needs this feature for other reasons, please respond and I'll reopen if necessary!
from inertia.
When converting an app to inertia I noticed this inconsistent behavior with pages that have Cache-Control: no-cache
. As this particular app I am working on benefits more on having the state reloaded when navigating back, due to its collaborative nature, I came with the following solution.
On your app.js
(the root component, so it is run only once) add this code to your mounted hook:
mounted() {
// ...other code
const reloadOnBack = () => {
this.$nextTick(() => {
this.$inertia.reload({preserveScroll: true, preserveState: false});
});
};
window.addEventListener('popstate', reloadOnBack);
this.$once('hook:beforeDestroy', function () {
window.removeEventListener('popstate', reloadOnBack);
});
},
Running this code on the mounted hook makes its popstate
handler to run after Inertia has set the page from history state, so Inertia will reload the navigated page data after inertia restored the previous page.
Ideally one should check the page's Cache-Control
headers to adhere to browser behavior, but as stated above, for this particular app - and its very low user base (a business internal tool) - I skipped the check and reload the page's data on every "history back" event.
I understand and agree with the goal to mimic the most of browser behavior, specially the back button, but as I needed this exception on a project I thought it would be worth to share.
from inertia.
Related Issues (20)
- Link component cannot be rendered as a custom component due to toLowerCase() HOT 1
- Incompatible with laravel vapor HOT 2
- Inertia crashes when a layer prop is not sent from server
- SSR | TypeError: Cannot read properties of undefined (reading 'getSSRProps') HOT 1
- Page doesn't get rendered HOT 1
- "undefined" is not valid JSON at JSON.parse in createInertiaApp() HOT 1
- Router methods type issues with wrong use of Exclude HOT 1
- [REQUEST] Router: make replace url optional HOT 2
- Form defaults() then reset() doesn't work as expected
- Make `data-page` hidration a new request HOT 7
- [1.1.0] Partial reload sets all $page props to undefined HOT 6
- [1.1.0] Partial reloads - Object props updated incorrectly HOT 1
- Unable to view Head attribute and <meta description> tag - When viewing source HOT 2
- Improvement on router HOT 12
- Data hydratation issue with partial reload on initial page visit HOT 2
- Please update docs HOT 6
- Query Param array gets repeated after second call to any router method HOT 1
- Edge Side Rendering (ESR) with Cloudflare Workers
- React: useForm Options - Replace History
- Major issues with inertia
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inertia.