react-router

Matching routes with hyphens in react-router

一世执手 提交于 2021-02-08 19:43:20
问题 I have URLs like this; http://0.0.0.0/country/bosnia-and-herzegovina-644 This is my Route declaration <Route path="/country/:countrySlug-:countryId" component={CountryPage} /> So this doesnt work as the hyphen breaks it, how can I change it so I only extract the last hyphen as the param, I don't really want to change my slug generation system to use a different character as these are the most readable IMHO, but are only used for information, not content loading. Thanks 回答1: I don't know if

Matching routes with hyphens in react-router

左心房为你撑大大i 提交于 2021-02-08 19:42:08
问题 I have URLs like this; http://0.0.0.0/country/bosnia-and-herzegovina-644 This is my Route declaration <Route path="/country/:countrySlug-:countryId" component={CountryPage} /> So this doesnt work as the hyphen breaks it, how can I change it so I only extract the last hyphen as the param, I don't really want to change my slug generation system to use a different character as these are the most readable IMHO, but are only used for information, not content loading. Thanks 回答1: I don't know if

Matching routes with hyphens in react-router

北城余情 提交于 2021-02-08 19:42:06
问题 I have URLs like this; http://0.0.0.0/country/bosnia-and-herzegovina-644 This is my Route declaration <Route path="/country/:countrySlug-:countryId" component={CountryPage} /> So this doesnt work as the hyphen breaks it, how can I change it so I only extract the last hyphen as the param, I don't really want to change my slug generation system to use a different character as these are the most readable IMHO, but are only used for information, not content loading. Thanks 回答1: I don't know if

Matching routes with hyphens in react-router

吃可爱长大的小学妹 提交于 2021-02-08 19:41:10
问题 I have URLs like this; http://0.0.0.0/country/bosnia-and-herzegovina-644 This is my Route declaration <Route path="/country/:countrySlug-:countryId" component={CountryPage} /> So this doesnt work as the hyphen breaks it, how can I change it so I only extract the last hyphen as the param, I don't really want to change my slug generation system to use a different character as these are the most readable IMHO, but are only used for information, not content loading. Thanks 回答1: I don't know if

React Router 4 and exact path with dynamic param

泄露秘密 提交于 2021-02-08 14:55:40
问题 I have issues with component being displayed on every single path because React Router 4 isn't using exact for that route (or so it appears). <Route path="/" exact component={Explore} /> <Route path="/about" component={About} /> // The one making problems <Route path="/:username" exact={true} render={props => <Profile {...props} />} /> So when I go to http://example.com/about, my Profile component is still being rendered. I guess the problem is in the route as it expects param :username and

Testing href value from a link component while having dynamic props

眉间皱痕 提交于 2021-02-08 13:45:53
问题 I am looking for a solution in order to still be able to use Link from react-router instead of a when testing href attribute value. Indeed, I have some components which change of route according to the context. However, when I am testing the href attribute value, the only thing returned is null. However, when I use an a, it returns me the expected value. Here is an failing test: import React from 'react'; import {Link} from 'react-router'; import TestUtils from 'react-addons-test-utils';

Set basename with react router

随声附和 提交于 2021-02-08 11:12:52
问题 I am using react-router and in that, I am using hashRouter . Now i have to deploy my react app in sub-directory of my website. So for that, I did: 1) Added homepage parameter in package.json file 2) Added <HashRouter basename={process.env.PUBLIC_URL}> Now, When I access my website URL localhost/react , I will be redirected to http://localhost/#/react/apps/ . But I want it to be redirected to http://localhost/react/#/apps/ . Note: I have to deploy react production build. My production build

TypeScript with React Lazy getting promise error

会有一股神秘感。 提交于 2021-02-08 10:57:25
问题 I am using react with typescript.I have used a higher order component to check whether the user is authenticated or not. After adding the hoc i am getting the error in routes as below /home/nidhin/Documents/Nidhinbackup/F/iot-remsys-demotwo/remsys/src/navigation/routes.ts TypeScript error in /home/nidhin/Documents/Nidhinbackup/F/iot-remsys-demotwo/remsys/src/navigation/routes.ts(7,36): Type 'Promise<typeof import("/home/nidhin/Documents/Nidhinbackup/F/iot-remsys-demotwo/remsys/src/pages

TypeScript with React Lazy getting promise error

青春壹個敷衍的年華 提交于 2021-02-08 10:52:30
问题 I am using react with typescript.I have used a higher order component to check whether the user is authenticated or not. After adding the hoc i am getting the error in routes as below /home/nidhin/Documents/Nidhinbackup/F/iot-remsys-demotwo/remsys/src/navigation/routes.ts TypeScript error in /home/nidhin/Documents/Nidhinbackup/F/iot-remsys-demotwo/remsys/src/navigation/routes.ts(7,36): Type 'Promise<typeof import("/home/nidhin/Documents/Nidhinbackup/F/iot-remsys-demotwo/remsys/src/pages

How to override non-generic types such as @types/History for useHitory()?

风格不统一 提交于 2021-02-08 09:58:04
问题 My goal is to override 'History' type, so I can use pass eventKey props for (eventKey) => history.push(eventKey) , I could not override History type from useHistory() , it said "Type History is not generic". The current solution I did is const history: any = useHistory() but I believe it defeat the purpose of types. import { RouteConfigProps } from "app/routes/config"; import { RenderRoutes } from "app/routes/RenderRoutes"; import React from "react"; import { Nav, Navbar } from "react