-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route priorities #38
Comments
The ordering works the same way as in express. So |
@frenzzy you're right routes are resolved top->bottom, and after further investigation my problem is different. It look like route matching is not stopped after first matched route. so with
and path |
Yes, because the const anyRoute = {
path: '/'
action() {
if (condition) {
return undefined // skip this route
}
return 'page'
}
} Playground: https://jsfiddle.net/frenzzy/ko22k9cg/1/ |
I followed example from docs const routes = [
{ path: '/one', action: ({ render }) => render(<h1>Page One</h1>) },
{ path: '/two', action: ({ render }) => render(<h1>Page Two</h1>) }
];
function render(component) {
return Promise(resolve => {
ReactDOM.render(component, document.body, resolve);
});
} so all of my actions are returning |
const container = document.getElementById('root');
function render(component) {
return Promise((resolve, reject) => {
try {
ReactDOM.render(component, container, () => resolve(true /* something not falsy */));
} catch (err) { reject(err); }
});
} |
Router waits until your promise will be finished and if promise returns |
@koistya that corrects the issue, thanks! Would be good to include this in documentation. |
By the way I think it is much better to start render strictly after the navigation process completely finished. This will help to avoid a lot of troubles like this and make the code easier to understand. const routes = [
{ path: '/one', action() { return <div>One</div> } },
{ path: '/two', action() { return <div>Two</div> } },
{ path: '/*', action() { return <div>Not Found</div> } },
];
UniversalRouter
.resolve(routes, { path: '/one' })
.then(component =>
ReactDOM.render(component, document.getElementById('root'))
) Playground: |
Closing this as resolved. Please reopen if needed. |
Hi, in my project I along with route path like
/welcome
,/sign_in
(specific string matched) I have also path/:id
. I've found only way to match this route is to place it on top ofroutes
so it looks like:
And it seems kind of strange for routes to be resolved bottom->top, wouldn't it make more sense to go top->bottom? So it checks all routes first and if none matches then it comes to
/:id
?The text was updated successfully, but these errors were encountered: