어떻게 내 루츠.j스스 포착하십시오 _firebase_request_key 라우트를 정의하십시오 파일을 URL 에서 # 39 의 싱글 ',' 매개변수 값에 의해 생성된 후 프로세스를 리디렉션할 Twitter& 사인온을 그들위에 서버?
http://localhost:8000/#/signin?_k=v9ifuf&__firebase_request_key=blablabla
그러나 '찾았다' 는 다음과 같은 경로를 통해 인기를 설명하는 것은 러디어스파람 구성, 매개변수:
<Router>
<Route path="/" component={Main}>
<Route path="signin" component={SignIn}>
<Route path=":redirectParam" component={TwitterSsoButton} />
</Route>
</Route>
</Router>
이미 반응할 러우터 분석하고 그 위치를 당신꺼에요 전달하며 데이터베이스에구성원을 루테콤파넨스 을 소품. 쿼리하지 액세스할 수 있습니다 (vora? 통해 url 에) 부품
this.props.location.query.__firebase_request_key
길을 찾고 있다면 분판된 매개 변수 값을 가진 콜론 (:) 라우터인지, 내부의 그것은꿈의 통해 접근할 수 있도록
this.props.match.params.redirectParam
이 말 qic 반응할 러우터 v3 버전 (무엇인지 잘 모르시는). 이전 버전 사용 '' 티s.프로프슈스파르타 s.러디어스파람 러우터 것으로 보고되었다.
러우터 v4 언약보다는 반응할 수 있지만 더 이상 당신꺼에요 쿼리하지 구문 분석을 통해 이를 '전용 액세스보다 티s.프로프스트로카션.시치'. 사유 (참조 nbeuchat& # 39 의 오토메이티드.
E. g. 와 쿼리 문자열 '할 수 있는' qs 임포트된 tpc. 라이브러리
qs.parse(this.props.location.search, { ignoreQueryPrefix: true }).__firebase_request_key
[이 오토메이티드] 참조 (https://stackoverflow.com/a/53079875/969483) 에 대한 아이디어를 구문 분석 좀 더 검색을 구체화하십시오.
또한 '스위치' 의 하위 구성 요소가 아닌 경우 직접 사용하는 데 필요한 모든 러우터 제공한 액세스하려면 [비트루터] (https://reacttraining.com/react-router/web/api/withRouter) 소품.
일반
console.log(this.props)
어떤 경우든 데 도움이 될 것입니다.
<Route path="/users/:id" component={UserPage}/>
< span>;
this.props.match.params.id
구성 요소가 함께 자동 렌더링됩니다 라우트를 소품.
< br>;
<Route path="/users/:id" render={(props) => <UserPage {...props} />}/>
< span>;
this.props.match.params.id
소품 함수은 렌더링합니다 라우트를 전달됩니다.
러우터 v3 반응을 통해 얻을 수 있습니다 "에서 쿼리 문자열 티s.프로프스트로카션.시치 ' (=, = 파머 qs2 naisarg& qs1?). 예를 들어, '이제 params) = {qs1 크리스트링스파스 (티s.프로프스트로카션.시치)', '함께 줄 수 있을 것 "이라고 말했다. # 39, & # 39, naisarg&, qs2: # 39, & # 39 parmar&} '.
반응할 수 있는 '이' 티s.프로프스트로카시옹스케리 러우터 v4, 더 이상 존재하지 않습니다. '대신' 티s.프로프스트로카션.시치 사용해야 할 때 이 같은 방법으로 기존 패키지 사용하여 구문 분석 및 쿼리하지 매개변수입니다 교도관님도요 또는 '쿼리 문자열'.
여기서 사용한 예 '와' 는 최소 반응할 러우터 v4 쿼리 문자열 라이브러리란.
import { withRouter } from 'react-router-dom';
import queryString from 'query-string';
class ActivateAccount extends Component{
someFunction(){
let params = queryString.parse(this.props.location.search)
...
}
...
}
export default withRouter(ActivateAccount);
>. 인기 있는 여러 가지 패키지도 쿼리 문자열 구문 분석 / 스트린기프잉 약간 다르게 할 수도 있으며, 각 이러한 차이를 " correct"; 일부 사용자와 " 길을 incorrect"; 타인에 대한. 반응할 경우 러우터 꼽은 " right"; 어떤 사람들은 이벤트여야만 적합합니까 한 것이다. 그런 다음 경기에서 길을 추가해야 할 것이라고 다른 사용자에게 쿼리하지 그들이 선호하는 구문 분석 패키지. 검색을 통해 필요한 내부 사용할 수 없다는 반응을 러우터 redhat. 있기 때문에 문자열 구문 분석을 key-value 쌍, 이러한 어느쪽이야 선택할 수 있어야 한다고 doesn& t # 39 right" ";).
>. [.]
>. 4.0 은 스트립 out all the ", 배터리 included" 외곽진입 걸린 수 있다. 그냥 기본 기능 및 물러서요 사람이었는가부텀 라우팅할 수 있습니다. 쿼리 문자열 구문 분석 또는 비동기 로딩하거나 러더스 하는 경우 통합 또는 다른 어떤 것에 매우 구체적인 관심용 있는 라이브러리를 사용하여 특별히 단축시킵니다 览侩 荤례 추가할 수 있습니다. # 39 의 쓸모 있는 덜 수 있는, t 는 압축됨 don& 필요성과 특정 환경 설정 및 요구에 데이터베이스에구성원을 셨으며 사용자정의할 수 있습니다.
전체 논의가 깃허브 에서 찾을 수 있습니다.
V4 를 사용하는 것이 위한 솔루션 외부 라이브러리 [쿼리 문자열] (https://github.com/sindresorhus/query-string) '이' 프로프스트로카션.시치 구문 분석
const qs = require('query-string');
//or
import * as qs from 'query-string';
console.log(location.search);
//=> '?foo=bar'
const parsed = qs.parse(location.search);
console.log(parsed);
//=> {foo: 'bar'}
세 가지 방법을 내린 것으로 알고 그렇게 할 수 있습니다.
1.use 정규식이 afaq 쿼리하지 구체화하십시오.
2.you 있지만브라우저에 api 를 사용할 수 있습니다. 현재 url 은 다음과 같은 이미지
http://www.google.com.au?token=123
우린 그냥 123 원하고 있습니다.
첫 번째
const query = new URLSearchParams(this.props.location.search);
그럼
const token = query.get('token')
console.log(token)//123
첫 번째 설치하는 것이
내가 쿼리 문자열 고궁박물원 현재 가져갈 javascript 파일을:
다음 단계는 # 39, & # 39 token& 얻을 수 있습니다. 현재 uirl 다음과 같이 합니다.
const value=queryString.parse(this.props.location.search);
const token=value.token;
console.log('token',token)//123
희망을 줍니다.
앱 =, =, = 160990 a-id article& home& 등에 관한 법률 (http://www.google.com.au?
우리는 함수를 정의하여 내려받습니다 매개변수입니다:
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
console.log(query)//"app=article&act=news_content&aid=160990"
var vars = query.split("&");
console.log(vars) //[ 'app=article', 'act=news_content', 'aid=160990' ]
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
console.log(pair)//[ 'app', 'article' ][ 'act', 'news_content' ][ 'aid', '160990' ]
if(pair[0] == variable){return pair[1];}
}
return(false);
}
getQueryVariable('aid') //160990
const urlParams = new URLSearchParams(this.props.location.search)
const key = urlParams.get('__firebase_request_key')
이 회사는 현재 유념하십시오 실험.
브라우저 호환성 확인할 수 있습니다. # Browser_compatibility https://developer.mozilla.org/en-us/docs/web/api/urlsearchparams/urlsearchparams
이후 더 이상 반응하지 러우터 '에서' v4 '직접' 의 '위치' 객체에는 params 쿼리하지 얻을 수 있습니다. 그 이유는 있다.
>. 인기 패키지 등 여러 가지 않는 쿼리 문자열 >. 이러한 parsing/stringifying 약간 다르게, 각 >. 수도 correct" 변경분 "; 일부 사용자와 " 길을 incorrect"; >. 타인에 대한. 반응할 경우 러우터 꼽은 " right"; 한 것이라는 이벤트여야만 >. 일부 사람들은 적합합니까. 그러면 다른 길을 추가해야 할 것이다 >. 사용자가 자신의 대체하십시오 쿼리하지 구문 분석 기본 패키지. There is >. 이를 통해 필요한 내부용 검색 문자열의 러우터 반응할 수 없습니다. >. 이 때문에 분석할 수 있어야 하는 doesn& key-value 쌍, t # 39 선택할 수 있습니다. >. one of these 제공하십시오 right" ";).
그냥 분석할 수 있는 포함되어 있을 것이라고 볼 수 있는 구성 요소를 더욱 감지에서 그냥 로카션.시치 쿼리하지 객체에는 기대하고 있다.
이 같은 '에서' 보통 '비트루터 반응을 러우터 재정의을 의해 이렇게 할 수 있습니다
커스트롬비트루트리아스
import { compose, withPropsOnChange } from 'recompose';
import { withRouter } from 'react-router';
import queryString from 'query-string';
const propsWithQuery = withPropsOnChange(
['location', 'match'],
({ location, match }) => {
return {
location: {
...location,
query: queryString.parse(location.search)
},
match
};
}
);
export default compose(withRouter, propsWithQuery)
import React from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'
// A simple component that shows the pathname of the current location
class ShowTheLocation extends React.Component {
static propTypes = {
match: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
history: PropTypes.object.isRequired
}
render() {
const { match, location, history } = this.props
return (
<div>You are now at {location.pathname}</div>
)
}
}
// Create a new component that is "connected" (to borrow redux terminology) to the router.
const TwitterSsoButton = withRouter(ShowTheLocation)
// This gets around shouldComponentUpdate
withRouter(connect(...)(MyComponent))
// This does not
connect(...)(withRouter(MyComponent))
내가 이 문제를 해결하기 위해 진땀을. 위의 작업 없는 경우 이 대신 시도해 볼 수 있습니다. 나는 앱을 만드는 데 시간이 사용하여
react-router-dom": " ^ 4.3.1";
라우터가 지정된 위치에서
<Route path="some/path" ..../>
이렇게 통과 할 수 있는 추가 &prs. 이름을 그녀의심장을
<Route path="some/path/:id" .../>
Where you are at the 페이지 렌더링 일부 / 경로를 볼 수 있습니다 이런 콜러 id 매개 변수 이름을 지정할 수 있습니다.
componentDidMount(){
console.log(this.props);
console.log(this.props.match.params.id);
}
At the end where you 익스포트를 기본
export default withRouter(Component);
반드시 포함시키십시오 가져오기의
import { withRouter } from 'react-router-dom'
당신이 약간만이라도 콘솔드로그 (티s.프로프스) 할 때 어떤 설정되었습니다 가미카제다. 이따봐
componentDidMount(){
//http://localhost:3000/service/anas
//<Route path="/service/:serviceName" component={Service} />
const {params} =this.props.match;
this.setState({
title: params.serviceName ,
content: data.Content
})
}
아마 조금 늦은 시간이 훅 도움을 줄 수 있지만 이 get / set 의 값을 uirl 쿼리하지: https://github.com/rudyhuynh/use-url-search-params (written by me).
작동하잖아 없이 '반응을 러우터'. 다음은 네 경우엔 코드 예제:
import React from "react";
import { useUrlSearchParams } from "use-url-search-params";
const MyComponent = () => {
const [params, setParams] = useUrlSearchParams()
return (
<div>
__firebase_request_key: {params.__firebase_request_key}
</div>
)
}
객체의 속성 및 기록, 가장 가까운 < 액세스하십시오 수 있습니다, & # 39 을 통해 일치시킵니다 Route> 비트루터 고차 구성 요소. 비트루터 해당되어서는 업데이트되도록 통과할 때마다, 위치 및 소품 랩된 컴포넌트인지 렌더링합니다 수 있다.
import React from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'
// A simple component that shows the pathname of the current location
class ShowTheLocation extends React.Component {
static propTypes = {
match: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
history: PropTypes.object.isRequired
}
render() {
const { match, location, history } = this.props
return (
<div>You are now at {location.pathname}</div>
)
}
}
// Create a new component that is "connected" (to borrow redux
// terminology) to the router.
const ShowTheLocationWithRouter = withRouter(ShowTheLocation)
또는 이 같은 일이 아닐까?
<! - begin 스니핏: js 숨기십시오: 거짓값 콘솔: 진정한 바벨. > 거짓값 -;
let win = {
'location': {
'path': 'http://localhost:8000/#/signin?_k=v9ifuf&__firebase_request_key=blablabla'
}
}
if (win.location.path.match('__firebase_request_key').length) {
let key = win.location.path.split('__firebase_request_key=')[1]
console.log(key)
}
끝 - < 스니핏 >;!
내가 사용하는 등 외부 패키지로의 쿼리 문자열 불렀으매 uirl 매개변수입니다 분석할 수 있습니다.
import React, {Component} from 'react'
import { parse } from 'query-string';
resetPass() {
const {password} = this.state;
this.setState({fetching: true, error: undefined});
const query = parse(location.search);
return fetch(settings.urls.update_password, {
method: 'POST',
headers: {'Content-Type': 'application/json', 'Authorization': query.token},
mode: 'cors',
body: JSON.stringify({password})
})
.then(response=>response.json())
.then(json=>{
if (json.error)
throw Error(json.error.message || 'Unknown fetch error');
this.setState({fetching: false, error: undefined, changePassword: true});
})
.catch(error=>this.setState({fetching: false, error: error.message}));
}