. Advertisement .
..3..
. Advertisement .
..4..
I am working on javascript, but I found the following warning message:
You should not use Route or withRouter() outside a Router
You should not use Link outside a Router
Is there any way to stabilize the issue “you should not use or withrouter() outside a ”?
I read a lot of topics about this, but all of them were trying to install anything. Is this the correct way, or any recommendation for me?
Please find the beginning command below:
import React, { Component } from 'react';
import { NavigationContainer, NavItem } from './navigationBar.style';
class NavigationBar extends Component {
render() {
return (
<NavigationContainer>
<NavItem to="/">Home</NavItem>
<NavItem to="/projects">Project</NavItem>
</NavigationContainer>
);
}
}
export default NavigationBar;
import styled from 'styled-components';
import { Flex, Div } from 'theme/grid';
import { NavLink } from 'react-router-dom';
export const NavigationContainer = styled(Flex)`
position: fixed;
right: 20px;
top: 0.5em;
font-size: 1em;
`;
export const NavItem = styled(NavLink)`
position: relative;
padding-left: 10px;
cursor: pointer;
`;
The cause: This warning is thrown to alert that
BrowserRouter
has not been specified and you are utilizingLink
,NavLink
, orRouter
components.The solution: To solve this problem, you define
BrowserRouter
in theindex.js
file to navigation to be available across your app.Import
BrowserRouter
from thereact-router-dom
package and wrap theApp
component with it in the index.js file.Wrap the main react render code within the Router. React-dom, for example, requires that you wrap the app using Browser-Router. This is the index.js file if this is a Udacity Project.