问题
I am new to react and am using okta react login.
function onAuthRequired({ history }) {
history.push("/login");
}
function SecureApp() {
return (
<Security
issuer="issuer name"
client_id="client id name"
redirect_uri={window.location.origin + "/callback"}
onAuthRequired={onAuthRequired}
>
<div className="App">
<SecureRoute path="/" exact={true} component={Dashboard} />
<SecureRoute path="/logout" exact={true} component={Login} />
<Route path="/login" render={() => <Login baseUrl={api.baseurl} />} />
<Route path="/callback" component={ImplicitCallback} />
</div>
</Security>
);
}
here In side dashboard component i am not able to create nested route
`<h1>dashboard</h1>
<ul>
<li>
<Link to={`${match.url}/projects`}>Projects</Link>
</li>
</ul>
<Route path={`${match.path}/projects`} component={Projects} />`
error: SecurityError: Failed to execute 'pushState' on 'History': A history state object with URL 'http://projects/' cannot be created in a document with origin 'http://localhost:3000' and URL 'http://localhost:3000/'.
回答1:
If you want to create your route with /projects then simply add your path to Route
<Route path='/projects' component={Projects} />
And you can access your route like
<Link to='/projects' >Projects</Link>
来源:https://stackoverflow.com/questions/59853605/not-able-to-create-nested-routes-with-okta-react-login