简体   繁体   English

React Router Deep Link 与动态

[英]React Router Deep Link with dynamic

I want deep link with dynamic route我想要动态路由的深层链接
My code is this我的代码是这个

import React from 'react';
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";

import Home from '../Routes/Home';
import Add from '../Routes/Add';
import Region from '../Routes/Region';
import Stores from '../Routes/Region/Stores';

function App() {
  return (
    <div className="App">
            <Router>
                <Switch>
                    <Route exact path="/" component={Home} />
                    <Route path="/addBook" component={Add} />
                    <Route path="/:region" component={Region} />
                    <Route path="/:region/:store" component={Stores} />
                </Switch>
                <Link to={`/${"ulsan"}`}>
                    <button>go</button>
                </Link>
            </Router>  
    </div>
  );
}

export default App;

and my region page is this我的地区页面是这个

import React from 'react';
import { Link } from 'react-router-dom';

function Region() {
    const store = "hello"
    return(
        <>

                <Link to={`/${"ulsan"}/${store}`}>
                    <button>store</button>
                </Link>
            <div>Region</div>
        </>
    )
}

export default Region;

when I click store button, page is staying Region当我点击商店按钮时,页面停留在区域
I don't know how to move Stoer page with dynamic route我不知道如何使用动态路由移动 Stoer 页面
what is the problem???问题是什么???

Sorry I'm not good at English对不起我英语不好

The Problem is how you declare your routes, you need to add exact attributs:问题是你如何声明你的路线,你需要添加确切的属性:

<Route exact path="/:region" component={Region} />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM