如何使用react路由器v6获取当前url的最后一部分?
例如:
如果当前路径是https://localhost:4200/example/example-details,那么我想这样检查它
const location = useLocation();
if (location.pathname === '/example-details')) {
// do some stuff here
}
..but,它总是返回完整的路径。
它适用于location.pathname.includes('/example-details'),但我很好奇是否有一种
我使用的是react路由器,我有以下代码:
let history = useHistory();
let goToReviewPage = () => history.push(`review/${productId}`);
我当前的url是:/foo/bar和调用goToReviewPage()将重定向到
/foo/review/${productId}而不是/foo/bar/review/${productId}
我不知道如何设置基本的道路将推动历史。
我试图使用react路由器为我的页面创建路由,但我总是收到以下错误:
**Warning: No route matches path "/profile/". Make sure you have <Route path="/profile/"> somewhere in your routes app.js:34**
这就是我的代码
var React = require('react');
var Router = require('react-router');
var Home = require
我目前正在开发一个react应用程序,直到最近我注意到我在public/html中定义的所有外部脚本在使用react router呈现页面时不再工作,但是当我直接调用页面时,一切都很好。
这些是我的html文件正文标记:
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script
defer
type="
我通过使用路由器参数来处理react组件,并且我已经使用componentDidMount事件生命cycle.It在状态下设置了路由器参数值,这符合我的要求,但是当我通过第二个路由器参数value.Please时,"componentDidMount“不会在第二次触发,检查下面的代码并建议如何做。
import React, { Component } from 'react';
import ConfigItem from '../../Config';
import axios from 'axios';
class ZohoDash