main.js
import React from 'react';
import {BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom';
import home from './home';
import about from './about';
import menu from './menu';
import gallery from './gallery';
import franchise from './franchise';
const Main = () => (
<Switch>
<Route exact path ="/" component={home} />
<Route path ="/about" component={about} />
<Route path ="/menu" component={menu} />
<Route path ="/gallery" component={gallery} />
<Route path ="/franchise" component={franchise} />
</Switch>
)
export default Main;
导航.js
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { Layout, Header, Navigation, Drawer, Content} from 'react-mdl';
import Main from './main';
export default class CustomNavbar extends Component {
render() {
return (
<div className="demo-big-content">
<Layout>
<Header title="CHEFSTYLE" scroll>
<Navigation>
<Link href="/" to="/">Home</Link>
<Link href="/about" to="/about">About</Link>
<Link href="/menu">Menu</Link>
<Link href="/gallery">Gallery</Link>
<Link href="/franchise">Franchise</Link>
</Navigation>
</Header>
<Drawer title="CHEFSTYLE">
<Navigation>
<Link href="/" to="/">Home</Link>
<Link href="/about" to="/about">About</Link>
<Link href="/menu">Menu</Link>
<Link href="/gallery">Gallery</Link>
<Link href="/franchise">Franchise</Link>
</Navigation>
</Drawer>
<Content>
<div className="page-content" />
<Main/>
</Content>
</Layout>
</div> )
}
}
错误:不变量失败:您不应在不变量之外使用 D:/pandemic/pandemicmateria/kupsmaterial/node_modules/tiny-invariant/dist/tiny-invariant.esm.js:11(匿名函数) D:/pandemic/pandemicmateria/modules /Link.js:84 如果我在 main.js 中使用 Router 标记而不是 Switch,并且如果我在 nav.js 中将导航标记与 Router 标记括起来,则我正在使用 react-mdl 进行 UI 反应,这意味着我没有收到任何错误但我没有得到输出......我的意思是页面没有相对于链接进行路由