6.0.0-alpha.5
https://codesandbox.io/s/serene-fermat-tchxk?file=/public/index.html:1379-1705
The sandbox shows a minimal, equivalent program with React Router @5.2.0, which is working.
Now, comment the v5 script tag under public/index.html and uncomment the v6 ones.
Script sources:
v5:
<script src="https://unpkg.com/[email protected]/umd/react-router-dom.min.js"></script>
v6:
<script src="https://unpkg.com/[email protected]/umd/react-router.production.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-router-dom.production.min.js"></script>
There is no error for v6, as with v5.
Error:
TypeError
t.useRef is not a function
I am not entirely sure about the cause, as useRef rather is React. I suspected it to be some kind of environment transpilation problem with Codesandbox. Though, I could reproduce an error outside Codesandbox as well.
I think react-router v6 requires hooks feature of React.
Hooks are a new addition in React 16.8 (https://reactjs.org/docs/hooks-intro.html)
I see your example in React 16.3.1 so that why it does not work.
Upgrade your React version. I upgraded React at your example to 16.13.1 and add
<script src="https://unpkg.com/[email protected]/umd/history.production.min.js"></script>
And it works: https://codesandbox.io/s/priceless-boyd-i8bxs?file=/public/index.html:0-2118
Yeah, don't know how I missed that when I first looked. It's the wrong version of React.
Most helpful comment
I think
react-routerv6 requires hooks feature of React.I see your example in React 16.3.1 so that why it does not work.
Upgrade your React version. I upgraded React at your example to 16.13.1 and add
And it works: https://codesandbox.io/s/priceless-boyd-i8bxs?file=/public/index.html:0-2118