答案是:不能?
一起来扒源码吧。
let createRoute = basepath => element => {
if (!element) { // Router的子元素
return null;
}
if (element.type === React.Fragment && element.props.children) { // 处理Fragment类型元素包裹的Route(简写:<></>)
return React.Children.map(element.props.children, createRoute(basepath));
}
invariant(
element.props.path || element.props.default || element.type === Redirect,
`<Router>: Children of <Router> must have a \`path\` or \`default\` prop, or be a \`<Redirect>\`. None found on element type \`${
element.type
}\``
);
invariant(
!(element.type === Redirect && (!element.props.from || !element.props.to)),
`<Redirect from="${element.props.from}" to="${
element.props.to
}"/> requires both "from" and "to" props when inside a <Router>.`
);
invariant(
!(
element.type === Redirect &&
!validateRedirect(element.props.from, element.props.to)
),
`<Redirect from="${element.props.from} to="${
element.props.to
}"/> has mismatched dynamic segments, ensure both paths have the exact same dynamic segments.`
);
// 以下处理 Redirect元素
if (element.props.default) {
return { value: element, default: true };
}
let elementPath =
element.type === Redirect ? element.props.from : element.props.path;
let path =
elementPath === "/"
? basepath
: `${stripSlashes(basepath)}/${stripSlashes(elementPath)}`;
return {
value: element,
default: element.props.default,
path: element.props.children ? `${stripSlashes(path)}/*` : path
};
};
除了 Fragment,Route,Redirect和其他内部约定的包含default属性的内部路由组件,其他html标签是不能生成正确的路由配置的。
So,如果你用了其他标签包裹Router子组件,页面对路由是不能正确响应的。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。