not able to create nested routes with okta react login

南楼画角 提交于 2020-01-25 06:38:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!