Interesting.
It appears to be because of how the Switch
component is implemented. The following snippet from the code is of particular interest:
let element, match;
React.Children.forEach(this.props.children, child => {
if (match == null && React.isValidElement(child)) {
element = child;
const path = child.props.path || child.props.from;
match = path
? matchPath(location.pathname, { ...child.props, path })
: context.match;
}
});
As you can see, the component simily looks through its children components and finds the path
prop. It assumes you've passed a proper path
prop to each Route
component.
So it doesn't matter that you removed the path
from your Route
, because the Switch will take the path
from your RouteWrapper
component.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…